Boolean datasource binding

4 posts, 1 answers
  1. Answer
    Jan Kaare
    Jan Kaare avatar
    16 posts
    Member since:
    Dec 2010

    Posted 14 Apr 2013 Link to this post

    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...
  2. Vladimir Iliev
    Vladimir Iliev avatar
    2199 posts

    Posted 17 Apr 2013 Link to this post

    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();
              ->template('<input type="checkbox" #= Discontinued ? checked="checked":"" # class="chkbx" />');
    $(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!
  3. Jan Kaare
    Jan Kaare avatar
    16 posts
    Member since:
    Dec 2010

    Posted 17 Apr 2013 Link to this post

    That json parameter JSON_NUMERIC_CHECK resulted in correct binding to the datasource.

  4. Emmanuel
    Emmanuel avatar
    7 posts
    Member since:
    Feb 2017

    Posted 20 Apr 2017 Link to this post

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

    dataItem.dirty = true;
Back to Top