EasyUI Forum
May 19, 2024, 06:57:46 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Poll
Question: Why datagrid checkbox load data always check all?
DataGrrid - 1 (100%)
Checkbox - 0 (0%)
Total Voters: 1

Pages: [1]
  Print  
Author Topic: DataGrid checkbox question.  (Read 9864 times)
frankgao
Jr. Member
**
Posts: 53


View Profile Email
« 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>
« Last Edit: October 03, 2015, 08:05:35 AM by frankgao » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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.
Logged
frankgao
Jr. Member
**
Posts: 53


View Profile Email
« Reply #2 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);
                        }
                    });
                }
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 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.
Logged
frankgao
Jr. Member
**
Posts: 53


View Profile Email
« Reply #4 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 }
        ]
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 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.
Logged
frankgao
Jr. Member
**
Posts: 53


View Profile Email
« Reply #6 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 }
        ]
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!