easyui datagrid no ID case, easyui datagrid delete rows of information method

The index passed directly in the datagrid easyui comes deletRow click method to delete the current line, the beginning and there is no problem, but when you delete or continuous problem.

The reason is that the line is a datagrid datagrid-row-index and datagrid-row-r1-xx to locate the line, if the start line of the index as a parameter to deleteRow method, each row index is fixed, the other index rows will not delete a row with the change out. Therefore, continuous deletion may occur when a row after deleting, click the Delete button in the second row, the third row is indeed deleted this situation.

Recently I was looking for some solutions, but are a little complicated, this solution only recently single, and share with everyone:

html:

<table id="dg" class="easyui-datagrid" title=""></table>

JS:

 1 $(function() {
 2                 $('#dg').datagrid().datagrid('enableCellEditing');//首行复选框
 3 
 4                 $('#dg').datagrid({
 5                     rownumbers: true,
 6                     multipleSelect:true,
 7                     collapsible: false,
 8                     pagination: true,
 9                     url: 'datagrid/dg.json',
10                     method: 'get',
11                     Columns: [
 12 is                          [{
 13 is                              Field: 'CK' ,
 14                              CheckBox: to true 
15                          }, {
 16                              Field: 'name' ,
 . 17                              title: 'name'
 18 is                          }, {
 . 19                              Field: 'Tel' ,
 20 is                              title: 'Mobile number '
 21 is                          }, {
 22 is                              Field:' Operate ' ,
 23 is                             title: '操作',
24                             formatter: function(val, row, index) {return '<button href="#" onclick="deleteRow(this)"></button>';
25                             }
26                         }]
27                     ]
28                 })
29             });
30 
31 
32 
33 function getRowIndex(target) {
34           var tr = $(target).closest('tr.datagrid-row');
35 36           return parseInt(tr.attr('datagrid-row-index')); 37 } 38 39 function deleteRow(target) { 40           alert(getRowIndex(target)); 41   $('#membershipCardData1').datagrid('deleteRow', getRowIndex(target)); 42 }

Address reprint: https://www.cnblogs.com/MinhongShen/p/7551717.html

Guess you like

Origin www.cnblogs.com/Dumb-dog/p/11539830.html