EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: aswzen on October 23, 2014, 06:54:06 AM



Title: how to delete multiple data in datagrid based on a criteria ?
Post by: aswzen on October 23, 2014, 06:54:06 AM
how to delete multiple data in datagrid based on a criteria ?

example i have datagrid like this one..
(http://i.imgur.com/J7uzNl1.jpg)

then i want to delete all data that branded 'PANASONIC'..

and this is my code
Code:
        var rows = $('#table_default').datagrid('getRows');
        var rowsLength = rows.length;
       
        for (i = 0; i < rowsLength; i++) {
            if (rows[i].BRAND_NAME == 'PANASONIC) {
                $('#table_default').datagrid('deleteRow', i);
            }
        }

but this code is not working properly..
do you know why??? IT'S BECAUSE the table index began to reindex again  the table after deleted a data..now i'm stuck to think another way...

NB and FYI :
i don't want to put the code in onLoadSuccess
any solution?

thanks in advance..


Title: Re: how to delete multiple data in datagrid based on a criteria ?
Post by: jarry on October 23, 2014, 07:42:50 AM
Please call 'getRowIndex' method to get the row index before deleting it.
Code:
var dg = $('#table_default');
var rows = dg.datagrid('getRows');
var rowsLength = rows.length;

var rr = [];
for (i = 0; i < rowsLength; i++) {
    if (rows[i].BRAND_NAME == 'PANASONIC) {
        rr.push(rows[i]);
    }
}
$.map(rr, function(row){
var index = dg.datagrid('getRowIndex', row);
dg.datagrid('deleteRow', index);
});


Title: Re: how to delete multiple data in datagrid based on a criteria ?
Post by: aswzen on August 13, 2015, 06:05:38 AM
its working thank you..  :)

i think this super important instruction must be written in documentation..