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

Does Grid fluent helper have feature for columns.selectable ?

1 Answer 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 11 Sep 2017, 09:57 PM

Kendo UI for jQuery documentation at http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.selectable states

"As of the Kendo UI R2 2017 SP1 release, the selection of columns with checkboxes is a built-in feature for the Grid..."

There does not seem to be a HtmHelper in Razor in Telerik UI for ASP.NET MVC for adding the selectable 'column' of checkboxes as in the manner shown for Kendo UI sample at https://dojo.telerik.com/ehaDo

In this sample, a SQL pivot view is surfaced to the page as a Grid<dynamic> because the pivot columns are unknown at coding time.  The DataTable of the pivot view is delivered via ViewBag so the Model can be built and fields added dynamically to the grid at init time.

There is no 'columns.Selectable()' as I might expect.

@(Html.Kendo().Grid<dynamic>()
   .Name("master")
   .DataSource(dataSource => dataSource
       .Ajax()
       .Model(model =>
       {
           var id = ViewBag.TestGridDataTable.PrimaryKey[0].ColumnName;
           model.Id(id);
           foreach (System.Data.DataColumn column in ViewBag.TestGridDataTable.Columns)
           {
               model.Field(column.ColumnName, column.DataType).Editable(false)
               ;
           }
       })
       .Read(read => read.Action("Read", "Results"))
   )
   .Columns(columns =>
   {
       columns.Selectable();  // <----- does not add a check box column
 
       foreach (System.Data.DataColumn column in ViewBag.TestGridDataTable.Columns)
       {
           columns.Bound(cn);
       }
   })

Do I have to create a new version of the model with an extra boolean field and go from there ?

1 Answer, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 13 Sep 2017, 11:29 AM
Hi,

Indeed there is an equivalent of the selectable option for MVC and you can find an example here. The main part is defining a select column as shown below.

C#
.Columns(columns => {
        columns.Select().Width(50);
        columns.Bound(p => p.ProductName);
        columns.Bound(p => p.UnitPrice).Width(140);
        columns.Bound(p => p.UnitsInStock).Width(140);
        columns.Bound(p => p.Discontinued).Width(100);
    })

That said you should be able to achieve the desired goal by modifying the code as follows.

C#
.Columns(columns =>
{
    columns.Select();
 
    foreach (System.Data.DataColumn column in ViewBag.TestGridDataTable.Columns)
    {
        columns.Bound(cn);
    }
})


Regards,
Angel Petrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or