Reputation: 1537
I have a grid like so:
<div class="div_100">
@Html.Grid(Model).Named("grid").Columns(columns =>
{
columns.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.Titled("Verzenden")
.RenderValueAs(n => Html.CheckBox("Verzonden", !n.Verzonden));
columns.Add(n => n.StartDatum).Titled("Start datum").Sortable(true).SetWidth(100);
columns.Add(n => n.EindDatum).Titled("Eind datum").Sortable(true).SetWidth(100);
columns.Add(n => n.Impact).Titled("Impact").Sortable(true).SetWidth(100);
columns.Add(n => n.NotificatieType.Type).Titled("Type").Sortable(true).SetWidth(100);
columns.Add(n => n.Omschrijving).Titled("Omschrijving").Sortable(true).SetWidth(100);
columns.Add(n => n.Diensten).Titled("Diensten").Sortable(true).SetWidth(100);
columns.Add(n => n.ID).Titled("ID").Sortable(true).SetWidth(100);
}).Filterable().SetLanguage("nl")
</div>
With quite some effort I've been able to add checkboxes.
now when i create the checkboxes i check them by default !n.Verzonden
= always false
i check them true by default since it's way less likely for one to be unchecked (9 out of 10 times they need to be checked so this saves the user some time)
Now when the user is done on this page and presses a button i want all the columns.Add(n => n.ID).Titled("ID")
ID's from the rows which are selected.
so how do i get all the ID's of the checked rows?
I'm currently using $.post
to communicate with my controller but maybe there's a better way, for example just sending the model, i used to populate the grid with, back by a submit button or something (not that good at the whole mvc thing yet)
EDIT
The rendered html:
<div class="div_100">
<div class="grid-mvc" data-lang="nl" data-gridname="grid" data-selectable="true" data-multiplefilters="false">
<div class="grid-wrap">
<table class="table table-striped grid-table">
<thead>
<tr>
<th class="grid-header" style="width:30px;">
<div class="grid-header-title">
<span>Verzenden</span>
</div>
</th>
<th class="grid-header" style="width:100px;">
<div class="grid-filter" data-filterdata="[]" data-name="StartDatum" data-type="System.DateTime" data-widgetdata="null">
<span class="grid-filter-btn" title="Filter this column"></span>
</div>
<div class="grid-header-title">
<a href="?grid-column=StartDatum&grid-dir=0">Start datum</a>
</div>
</th>
<th class="grid-header" style="width:100px;">
<div class="grid-filter" data-filterdata="[]" data-name="EindDatum" data-type="System.DateTime" data-widgetdata="null">
<span class="grid-filter-btn" title="Filter this column"></span>
</div>
<div class="grid-header-title"><a href="?grid-column=EindDatum&grid-dir=0">Eind datum</a></div>
</th>
<th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="Impact" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=Impact&grid-dir=0">Impact</a></div></th>
<th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="NotificatieType.Type" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=NotificatieType.Type&grid-dir=0">Type</a></div></th>
<th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="Omschrijving" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=Omschrijving&grid-dir=0">Omschrijving</a></div></th>
<th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="Diensten" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=Diensten&grid-dir=0">Diensten</a></div></th>
<th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="ID" data-type="System.Guid" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=ID&grid-dir=0">ID</a></div></th>
</tr>
</thead>
<tbody>
<tr class="grid-row ">
<td class="grid-cell" data-name="">
<input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" />
</td>
<td class="grid-cell" data-name="StartDatum">25-7-2014 10:00:00</td>
<td class="grid-cell" data-name="EindDatum">25-7-2014 11:00:00</td>
<td class="grid-cell" data-name="Impact">Volledige onderbreking</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Test</td>
<td class="grid-cell" data-name="Diensten">Volledige dienstverlening</td>
<td class="grid-cell" data-name="ID">3a2a53b9-d92a-4504-874d-5a901ad01041</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">25-7-2014 12:00:00</td>
<td class="grid-cell" data-name="EindDatum">25-7-2014 13:00:00</td>
<td class="grid-cell" data-name="Impact">Volledige onderbreking</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Test</td>
<td class="grid-cell" data-name="Diensten">Volledige dienstverlening</td>
<td class="grid-cell" data-name="ID">4c499f6c-53c8-49e0-b529-8b045819be10</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">25-7-2014 13:00:00</td>
<td class="grid-cell" data-name="EindDatum">25-7-2014 15:00:00</td>
<td class="grid-cell" data-name="Impact">Volledige onderbreking</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving"></td>
<td class="grid-cell" data-name="Diensten">Volledige dienstverlening</td>
<td class="grid-cell" data-name="ID">977885c5-4c12-431b-ab72-59383b1824c6</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">28-7-2014 10:00:00</td>
<td class="grid-cell" data-name="EindDatum">28-7-2014 11:00:00</td>
<td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Update print servers</td>
<td class="grid-cell" data-name="Diensten">Gedeeltelijke service</td>
<td class="grid-cell" data-name="ID">af4ed8cb-d033-47a4-96ae-f379bb484532</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">30-7-2014 10:00:00</td>
<td class="grid-cell" data-name="EindDatum">30-7-2014 14:00:00</td>
<td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Niets</td>
<td class="grid-cell" data-name="Diensten">Volledige service</td>
<td class="grid-cell" data-name="ID">f2388fba-27ab-417a-ab39-a221d9d82fd3</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">30-7-2014 10:00:00</td>
<td class="grid-cell" data-name="EindDatum">30-7-2014 14:00:00</td>
<td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Niets</td>
<td class="grid-cell" data-name="Diensten">Volledige service</td>
<td class="grid-cell" data-name="ID">3232fc33-0f82-4f76-a323-7ee988c4069a</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">30-7-2014 10:00:00</td>
<td class="grid-cell" data-name="EindDatum">30-7-2014 14:00:00</td>
<td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Niets</td>
<td class="grid-cell" data-name="Diensten">Volledige service</td>
<td class="grid-cell" data-name="ID">b9c2ff88-f469-49f0-a23c-86ddb8bf7808</td>
</tr>
<tr class="grid-row ">
<td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
<td class="grid-cell" data-name="StartDatum">31-7-2014 11:00:00</td>
<td class="grid-cell" data-name="EindDatum">31-7-2014 14:00:00</td>
<td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
<td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
<td class="grid-cell" data-name="Omschrijving">Niets</td>
<td class="grid-cell" data-name="Diensten">Volledige service</td>
<td class="grid-cell" data-name="ID">ecaa15da-0b91-4410-97ad-ba58148ebe4f</td>
</tr>
</tbody>
</table>
</div>
</div>
Upvotes: 0
Views: 1087
Reputation:
Try
$('input:checked').each(function () {
var row = $(this).closest('tr');
var ID = row.children('td').eq(7).text();
alert(ID); // for testing - don't know what you want to do with the ID's
});
Upvotes: 1