Column for multiselection

Oct 25, 2012 at 11:52 AM
Edited Oct 25, 2012 at 11:52 AM

Is it possible to add a column not connected with model but with raw html

where i add a input type='checkbox'  for multiselection ?

PS: also in header ?

 

Thank You

Coordinator
Oct 25, 2012 at 1:36 PM

Creating not connected  column is possible. Read thi thread - http://gridmvc.codeplex.com/discussions/399886

Creating custom header renderer is not support now. In which scenario you need this functionallity? But you can create a custom cshtml template (like _Grid.cshtml).

Oct 25, 2012 at 1:49 PM
Edited Oct 25, 2012 at 1:49 PM

I would like multiselection,

on row I used :

    columns.Add()
        .Encoded(false)
        .Sanitized(false)
        .RenderValueAs(d => Html.Raw("<input type='checkbox' name='chksel' class='foo' value='" + d.Id.ToString() + "' id='chksel" + d.Id.ToString() + "' onclick='CheckSelected()' /><label for='chksel" + d.Id.ToString() + "'></label>"));

 

I would also add a checkbox on header for "Select All"

 

Any suggestion ?

Coordinator
Oct 25, 2012 at 2:09 PM
Edited Oct 25, 2012 at 2:10 PM

For this purpose you can add a checkbox on the client side via javascript, something like this (using jQuery):

 

var checkallBox = $(document.createElement("input")).attr({ id: 'checkallitems', name: "CheckedAll", value: "true", type: 'checkbox', checked: false });   

$(".grid-table thead th").eq(0).append(checkallBox);   

checkallBox.click(function () {        $(".chksel").attr("checked", $(this).is(":checked"));    });

Oct 25, 2012 at 2:14 PM

I know how select all, but I don't know how put a checkbox on header.

Coordinator
Oct 25, 2012 at 2:16 PM

$(".grid-table thead th").eq(0).append(checkallBox);    - this line adds a checkbox to the first column in the grid

Oct 25, 2012 at 2:46 PM

ops.. sorry

yes run !!

Thank You.

 

PS: very nice project !!