EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: mzeddd on January 11, 2013, 05:42:37 AM



Title: datagrid: How to set checkbox state during data load
Post by: mzeddd on January 11, 2013, 05:42:37 AM
I have datagrid and I would like to set checkbox to correct state when I load JSON data.

In DEMO I have not found example how to exactly what I would like to have. It contains only how to enable checkboxes.

Also would be good to know how to check if item is selected or not

Thanks


Title: Re: datagrid: How to set checkbox state during data load
Post by: mzeddd on January 11, 2013, 07:00:46 AM
Very interesting thing: Good idea comes right after you port a question.

My question is over.
Thanks to myself. Very glad to talk to again  ;D

Here is the answer:
Code:
onLoadSuccess:function(data){
    var rows = $(this).datagrid('getRows');
    for(i=0;i<rows.length;++i){
        if(rows[i]['ck']==1) $(this).datagrid('checkRow',i);
    }
}


Title: Re: datagrid: How to set checkbox state during data load
Post by: mzeddd on January 25, 2013, 08:29:32 AM
New question about checkbox:es in datagrid.

For example I have datagrid with checkbox field as the 1st field.

Code:
$('#thisOne').datagrid({
columns:[[
{field:'ck',title:'',checkbox:true},
{field:'name',title:'Name',width:270}
]],
onLoadSuccess: function(data){
// some actions if needed
}
});
This means when I set checkbox in table heading all the records in the datagrid becomes 'checked'.

But when I load new data into this datagrid I have all records in initial state (not or partly 'checked') but checkbox in table header stays in 'checked' state.

It is not good. Is'nt it?

Could we consider this it easyui issue or developer should take care of this by himself? And how?


Title: Re: datagrid: How to set checkbox state during data load
Post by: 2plus2 on April 26, 2013, 11:45:27 AM
Here's a bit more of efficient code:

Code:
                        onLoadSuccess: function (data) {
                            for (i = 0; i < data.rows.length; ++i) {
                                if (data.rows[i]['ck'] == 1) $(this).datagrid('checkRow', i);
                            }
                        }

What would be nice is if the load function - when the checkbox is active - looked for a "Selected" column and auto-checked the row for you. (Hint. Hint.)