EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: frankgao on October 03, 2015, 08:02:58 AM



Title: DataGrid checkbox question.
Post by: frankgao on October 03, 2015, 08:02:58 AM
Hi all,

In my page,there have one datagrid component,the first column is checkbox.
When the data load,only two data checked value are true,all the others are false,but the datagrid display each row is selected.
Please help me.
Thank you.

Code:

<table id="gridmaster"></table>

<script>
    $(function () {
        $('#gridmaster').datagrid({
            title: '',
            url: '/Box/Company/GetJsonFunctionGrid',
            method: 'get',
            width: '700',
            rownumbers: true,
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'sysfunnumber', title: 'sysfunnumber' }
            ]],
            queryParams: {
                        id: id,
            },
            singleSelect: false,
            selectOnCheck: true,
            checkOnSelect: true,
            onLoadSuccess: function (data) {
                if (data) {
                    $.each(data.rows, function (index, item) {
                        if (item.checked) {
                            $('#gridmaster').datagrid('checkRow', index);
                        }
                    });
                }
            }
        });
    });
</script>


Title: Re: DataGrid checkbox question.
Post by: stworthy on October 04, 2015, 03:26:54 AM
What is the data returned from '/Box/Company/GetJsonFunctionGrid'? Please check the 'checked' property value in each rows.


Title: Re: DataGrid checkbox question.
Post by: frankgao on October 04, 2015, 03:41:16 AM
What is the data returned from '/Box/Company/GetJsonFunctionGrid'? Please check the 'checked' property value in each rows.

O,Thank you reply to me,I waiting for someone reply to me all day.this question prevent me go on several days.
The 'checked' property value only two rows are true,other 98 rows are false.
I annotation bottom of the code. Every rows checkbox are checked. i don't know why.

Code:
if (data) {
                    $.each(data.rows, function (index, item) {
                        if (item.checked) {
                            $('#gridmaster').datagrid('checkRow', index);
                        }
                    });
                }


Title: Re: DataGrid checkbox question.
Post by: stworthy on October 04, 2015, 03:58:18 AM
If you get all rows checked, the 'checked' property values in all rows are surely true. Please refer to this example http://jsfiddle.net/55a5nsq9/. It works fine.


Title: Re: DataGrid checkbox question.
Post by: frankgao on October 04, 2015, 05:26:07 AM
If you get all rows checked, the 'checked' property values in all rows are surely true. Please refer to this example http://jsfiddle.net/55a5nsq9/. It works fine.

Thank you.
Your code works fine.
Maybe I know the cause.Like bottom of the code.The id=5 is fine.The checkbox is not check,but the id=4 is not fine.
'false' and false.
Add the single quotes and no single quotes.if no single quotes it's fine. but add single quotes it's not fine.it's checked.
Why?

Code:
var data = [
          { id: 1, sysfunnumber: 'sysfunnumber1' },
          { id: 2, sysfunnumber: 'sysfunnumber2', checked: 'true' },
          { id: 3, sysfunnumber: 'sysfunnumber3', checked: 'true' },
          { id: 4, sysfunnumber: 'sysfunnumber4', checked:'false' },
          { id: 5, sysfunnumber: 'sysfunnumber5', checked: false }
        ]


Title: Re: DataGrid checkbox question.
Post by: stworthy on October 05, 2015, 02:07:42 AM
If you set the 'checked' value with 'true' or 'false', you get a string value. A non-empty string evaluates to true.


Title: Re: DataGrid checkbox question.
Post by: frankgao on October 06, 2015, 04:32:19 PM
If you set the 'checked' value with 'true' or 'false', you get a string value. A non-empty string evaluates to true.

No,
If set the 'checked' value with false or 'false' the result is different.the id=4 and id=5 is different work.
When id=4 the checkbox is checked,when id=5 the checkbox is not checked.Please note the single quotes.
You can test it.
Thanks.

Code:
var data = [
          { id: 1, sysfunnumber: 'sysfunnumber1' },
          { id: 2, sysfunnumber: 'sysfunnumber2', checked: 'true' },
          { id: 3, sysfunnumber: 'sysfunnumber3', checked: 'true' },
          { id: 4, sysfunnumber: 'sysfunnumber4', checked:'false' },
          { id: 5, sysfunnumber: 'sysfunnumber5', checked: false }
        ]