How to set the 'Select()' (checkbox) column of the MVC Grid?

6 posts, 1 answers
  1. Ed
    Ed avatar
    3 posts
    Member since:
    Nov 2017

    Posted 07 Feb 2018 Link to this post

    Hi,

    Please can anyone show me how I can set the value of a Select() column in the MVC grid?

    I have a class which contains a boolean field that I would like to use to tick / untick the checkbox that the Select() column renders, but I can find no information on how to do it!

     

    Any help greatly appreciated - please let me know if you require more info.

    Thanks..Ed

     

  2. Stefan
    Admin
    Stefan avatar
    2880 posts

    Posted 09 Feb 2018 Link to this post

    Hello, Ed,

    The Select column is only for selection purposes and it is not a bound column.

    The Boolean fields can be bound to a standard column and the Grid will automatically make a checkbox in edit mode.

    This could be observed in our editing demo:

    https://demos.telerik.com/aspnet-mvc/grid/editing

    Let me know if you need additional details on this matter.

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Ed
    Ed avatar
    3 posts
    Member since:
    Nov 2017

    Posted 27 Feb 2018 in reply to Stefan Link to this post

    Hi Stefan - thanks for the response.

    I decided to implement a custom solution using jQuery and a ClientTemplate, as my requirements were not really inline with the demo.

    I'm surprised you can't interact programmatically with the Select column though. Perhaps you could suggest this as an improvement to the framework, as it seems like an obvious thing to be able to do.

    Thanks..Ed

  4. Answer
    Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1009 posts

    Posted 01 Mar 2018 Link to this post

    Hi, Ed,

    It is possible to preselect certain checked state of some rows, however, it should be done programmatically on the dataBound event of the Kendo UI Grid. We have a Knowledge Base article which shows how to do that at: 

    https://docs.telerik.com/kendo-ui/knowledge-base/checkbox-selection-select-rows-on-load

    In your scenario, you can check if the boolean property of the dataItem is true or false and select the row as desired:

    dataBound: function(e) {
        var grid = this;
        var rows = grid.items();
        $(rows).each(function(e) {
          var row = this;
          var dataItem = grid.dataItem(row);
     
          if (dataItem.Discontinued) {
            grid.select(row);
          }
        });
    },

    https://dojo.telerik.com/ocOnIkEt

    Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Ed
    Ed avatar
    3 posts
    Member since:
    Nov 2017

    Posted 01 Mar 2018 in reply to Alex Hajigeorgieva Link to this post

    Awesome, thanks - that's exactly what I was looking for!

    Unfortunately I've already got a jQuery solution working, but will know for next time (and help others).

    Cheers..Ed

  6. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1009 posts

    Posted 02 Mar 2018 Link to this post

    Hello, Ed,

    Thank you for your feedback.

    I am glad the suggestion is appropriate. Hopefully, it will assist someone in the future indeed.

    Kind Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top