Title: How to empty a datagrid? Post by: wilfo on June 06, 2012, 11:47:57 PM I was adding rows to a datagrid but when i got last index i can't deleted.I am not using ajax only javascript.
sourcode: $("#btn_remove").click(function(){ var row = $('#tt').datagrid('getSelected'); $("#tt").datagrid('deleteRow',row.id); //could be $("#tt").datagrid('deleteRow',1);//but not delete the first one }); //adding row $("#btn_add").click(function(){ cont++; $('#tt').datagrid('insertRow',{ index: 0, // index start with 0 row: { id: cont, producto:'Aceite de oliva', precio:2.7, cantidad:5, total:13.5 } }); }); Please help , i need delete each selected row. Title: Re: How to empty a datagrid? Post by: stworthy on June 07, 2012, 06:01:19 PM The 'deleteRow' method require a 'index' parameter that represent the row index. Please pass a correct parameter value while calling this method. The example below shows how to delete all selected rows.
Code: var rows = $('#tt').datagrid('getSelections'); // get all selected rows Title: Re: How to empty a datagrid? Post by: ejzhang on July 02, 2012, 05:25:40 AM load a empty dataset
Code: $('#dg').datagrid('loadData', {"total":0,"rows":[]}); Title: Re: How to empty a datagrid? Post by: skellenb on July 03, 2012, 08:31:33 AM The 'deleteRow' method require a 'index' parameter that represent the row index. Please pass a correct parameter value while calling this method. The example below shows how to delete all selected rows. Code: var rows = $('#tt').datagrid('getSelections'); // get all selected rows this doesn't work for me... when first row was removed, the index doesn't correspond to the selected rows... For Example: When you have selected 4 rows (1,2,3,4) and you remove row 1 (index 0) so row 2 becomes now row 1 (index 0) and so on... For that Reason i push every index first in an array... then sort it and reverse it so that the first index to be removed is the last... then all lower indexes remain unchanged until you remove it... so i had to modify it like this below: Code: var rows = $('#tt').datagrid('getSelections'); // get all selected rows Title: Re: How to empty a datagrid? Post by: Ellipsis on November 01, 2012, 02:41:47 AM I tried the same methods on a combogrid,
first I call Code: $('#cc').combogrid('clear'); // the label and value are cleared OK The I start: Code: var rows = $('#cc').combogrid('grid').datagrid('getRows'); // get all rows The datagrid is not cleared :( Title: Re: How to empty a datagrid? Post by: Kevin on November 17, 2012, 07:17:54 PM @skellenb
There is an easier way (and quicker :)) var rows = $('#tt').datagrid('getSelections'); // get all selected rows for(var i=rows.length-1; i>= 0; i--){ var index = $('#tt').datagrid('getRowIndex',rows.id); // get the row index $('#tt').datagrid('deleteRow',index); } |