$(function () { let url = `http://8.135.106.227:8004/` let gName = 'Gridtable' let grtable = document.querySelector("#gridtb") grtable.GM({ gridManagerName: gName, height: '400px', ajaxData: function (setting) { // 传入分页及排序的配置项 return getList(Object.assign({}, setting.pageData, setting.sortData)); }, ajaxType: "POST", checkboxConfig: { useRowCheck: true, useRadio: true, }, query: { pluginId: 1 }, supportAjaxPage: true, columnData: [ { key: "code", text: "硬件编号", }, { key: "devTypeName", text: "硬件类型", }, { key: "name", text: "热点名字", }, { key: "id", text: "id", } ], }); // 确认事件 $('#gcommit').click(function () { let item = Array.from(GridManager.getCheckedTr(gName)) if (item.length<=0) { alert('请选择设备') return } alert(item) console.log(GridManager.getCheckedTr(gName)); }) // 取消事件 $('#gcancel,.gr-header>img').click(function () { $('.jsGrid-body').hide() console.log(GridManager.getCheckedTr(gName)); }) //搜索事件 $('.gr-header > .search').click(function () { var _query = { title: document.querySelector('[name="title"]').value, type: document.querySelector('[name="type"]').value, content: document.querySelector('[name="content"]').value, cPage: 1 }; grtable.GM('setQuery', _query, function(){ console.log('setQuery执行成功'); }); }) //设备添加 $('#grAdd').click(function () { $('.jsGrid-body').show() }) //设备删除 $('#grDel').click(function () { }) // 阻止冒泡 $('.jsGrid-con').on('click keydown keyup keypress',function (event) { event.stopPropagation(); }) let getList = function(params) { return new Promise((resolve, reject) => { $.ajax({ method: 'GET', headers: { 'Content-Type': 'application/json' }, dataType: 'json', contentType: 'application/json', url: url + 'api/device/list', success: function(data) { console.log(data); if (data.code === 0) { resolve({ ...data, totals:data.data.length }); } else { reject(data); } } }) }) }; })