$(function () { $("#jqGrid").jqGrid({ url: '../collect/list', datatype: "json", colModel: [ {label: 'id', name: 'id', index: 'id', key: true, hidden: true}, {label: '用户', name: 'userName', index: 'user_name', width: 180}, {label: '商品', name: 'valueName', index: 'value_name', width: 670}, {label: '添加时间', name: 'addTime', index: 'add_time', align:'center',width: 160} // {label: '提醒', name: 'isAttention', index: 'is_attention', width: 80} // {label: '类型', name: 'typeId', index: 'type_id', width: 80} ], viewrecords: true, height: 550, rowNum: 10, rowList: [10, 30, 50], rownumbers: true, rownumWidth: 25, autowidth: true, shrinkToFit: false, autoScroll: true, //开启水平滚动条 width: 1500, multiselect: true, pager: "#jqGridPager", jsonReader: { root: "page.list", page: "page.currPage", total: "page.totalPage", records: "page.totalCount" }, prmNames: { page: "page", rows: "limit", order: "order" }, beforeSelectRow: function(rowid, e){ jQuery("#jqGrid").jqGrid('resetSelection'); return(true); }, gridComplete: function () { $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"}); } }); var myGrid = $("#jqGrid"); $("#cb_"+myGrid[0].id).hide(); }); var vm = new Vue({ el: '#rrapp', data: { showList: true, title: null, collect: {}, q: { name: '' } }, methods: { query: function () { vm.reload(); }, add: function () { vm.showList = false; vm.title = "新增"; vm.collect = {}; }, update: function (event) { var id = getSelectedRow(); if (id == null) { return; } vm.showList = false; vm.title = "修改"; vm.getInfo(id) }, saveOrUpdate: function (event) { var url = vm.collect.id == null ? "../collect/save" : "../collect/update"; $.ajax({ type: "POST", url: url, contentType: "application/json", data: JSON.stringify(vm.collect), success: function (r) { if (r.code === 0) { alert('操作成功', function (index) { vm.reload(); }); } else { alert(r.msg); } } }); }, del: function (event) { var ids = getSelectedRows(); if (ids == null) { return; } confirm('确定要删除选中的记录?', function () { $.ajax({ type: "POST", url: "../collect/delete", contentType: "application/json", data: JSON.stringify(ids), success: function (r) { if (r.code == 0) { alert('操作成功', function (index) { $("#jqGrid").trigger("reloadGrid"); }); } else { alert(r.msg); } } }); }); }, getInfo: function (id) { $.get("../collect/info/" + id, function (r) { vm.collect = r.collect; }); }, reload: function (event) { vm.showList = true; var page = $("#jqGrid").jqGrid('getGridParam', 'page'); $("#jqGrid").jqGrid('setGridParam', { postData: {'name': vm.q.name}, page: page }).trigger("reloadGrid"); } } });