EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: aswzen on June 02, 2014, 02:59:08 AM



Title: automatic check/select data in datagrid
Post by: aswzen on June 02, 2014, 02:59:08 AM
I think you missed something in datagrid demo...  :'(

How to create a datagrid with some data already checked or selected?

I found method in docs about using selectRow and checkRow..
but it just worked only in client side (checked or selected after datagrid successfully loaded).....

Code:
<table id="package_group_table" class="easyui-datagrid" style="width:250px;height:150px"
                data-options="url:admin/packagegroup/list_package_group_for_checkbox',singleSelect:false">
                        <thead>
                            <tr>
                                <th data-options="field:'PACKAGE_GROUP_ID'">ID</th>
                                <th data-options="field:'PACKAGE_GROUP_ALIAS'">Name</th>
                                <th data-options="field:'CHECKED'"   formatter="formatCheck">Status</th>
                                <th data-options="field:'CHECKED_STATUS',checkbox:true">Ck</th>
                            </tr>
                        </thead>
                    </table>
                    <input type="button" onclick="wawa();" value="tes"></input>
                    <script type="text/javascript">
                        function formatCheck(val,row,idx){
                            if(val+'' == 'true'){
                                $('#package_group_table').datagrid('checkRow', idx);
                            }
                        }
                    </script>

Code above isnt working...
CHECKED field populated with true and false data...


Title: Re: automatic check/select data in datagrid
Post by: aswzen on June 03, 2014, 03:29:45 AM
help please ....


Title: Re: automatic check/select data in datagrid
Post by: jarry on June 03, 2014, 07:50:23 AM
The 'checkRow' method must be called after loaded data successfully, so please do the checking rows in the 'onLoadSuccess' event.
Code:
<table id="package_group_table" class="easyui-datagrid" style="width:250px;height:150px"
    data-options="url:admin/packagegroup/list_package_group_for_checkbox',singleSelect:false,
    onLoadSuccess:function(){
var rows = $(this).datagrid('getRows');
for(var i=0; i<rows.length; i++){
if (rows[i]['CHECKED']){
$(this).datagrid('checkRow',i);
}
}   
    }
    ">
    <thead>
        <tr>
            <th data-options="field:'PACKAGE_GROUP_ID'">ID</th>
            <th data-options="field:'PACKAGE_GROUP_ALIAS'">Name</th>
            <th data-options="field:'CHECKED'">Status</th>
            <th data-options="field:'CHECKED_STATUS',checkbox:true">Ck</th>
        </tr>
    </thead>
</table>


Title: Re: automatic check/select data in datagrid
Post by: ryupanqui on June 03, 2014, 04:01:15 PM
I would know about this. Why this is not a default behaviour of datagrid? Because I think the problem is that developer will have to repeat this same code  in the 'onLoadSuccess' event of each datagrid. Thanks in advance for your reply!