This is a migrated thread and some comments may be shown as answers.

Boolean datasource binding

3 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jan Kaare
Top achievements
Rank 2
Jan Kaare asked on 14 Apr 2013, 09:06 PM
By utilizing the PHP wrapper, I have set a grid field as type boolean.

The field however does not bind to the datasource, as the field ends up with value false even when datasource field value is 1 (true).

In MySQL database, the field was first set to TINYINT(1) then to BOOLEAN with same resulting missing binding.

How to bind such a grid field to a boolean datasource field?

And how to let this boolean field come up as a checkbox, not as true & false? I think such boolean fields in general should always end up as checkboxes by default, not as true & false, yes & no etc...

3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 17 Apr 2013, 08:14 AM
Hi Jan,

 
Most probably the json_encode method is converting the numbers for the boolean propety to strings - could you please try to add the "JSON_NUMERIC_CHECK" parameter and let us know of the result:

echo json_encode($result, JSON_NUMERIC_CHECK);

Also you can make the column to display checkbox instead of true/false using column template:
$discontinued = new \Kendo\UI\GridColumn();
$discontinued->field('Discontinued')
          ->width(100)
          ->template('<input type="checkbox" #= Discontinued ? checked="checked":"" # class="chkbx" />');
JavaScript:
$(function () {
    //change #grid with your grid name
    $('#grid').on('click', '.chkbx', function () {
        var checked = $(this).is(':checked');
        var grid = $('#grid').data('kendoGrid');
        var dataItem = grid.dataItem($(this).closest('tr'));
        dataItem.set('Discontinued', checked);
    })
})

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jan Kaare
Top achievements
Rank 2
answered on 17 Apr 2013, 06:13 PM
That json parameter JSON_NUMERIC_CHECK resulted in correct binding to the datasource.

Thanks!
0
Emmanuel
Top achievements
Rank 1
answered on 20 Apr 2017, 09:22 AM

I had to add the following line in order to be able to save my changes:

dataItem.dirty = true;
Tags
Grid
Asked by
Jan Kaare
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Jan Kaare
Top achievements
Rank 2
Emmanuel
Top achievements
Rank 1
Share this question
or