EasyUI Forum
May 03, 2024, 01:27:16 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: datagrid: How to set checkbox state during data load  (Read 41896 times)
mzeddd
Full Member
***
Posts: 223



View Profile
« 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
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #1 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  Grin

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);
    }
}
« Last Edit: January 11, 2013, 02:03:24 PM by mzeddd » Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #2 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?
« Last Edit: January 25, 2013, 11:39:58 AM by mzeddd » Logged
2plus2
Jr. Member
**
Posts: 75


View Profile
« Reply #3 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.)
« Last Edit: April 26, 2013, 11:47:24 AM by AnthonyBaratta » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!