how to get the selected checkox rows form hidden pages in jquery datatable
how to get the selected checkox rows form hidden pages in jquery datatable
denfer
Posts: 3Questions: 1Answers: 0
I'm using jquery datatables with the first column as CheckBox
How I can get in javascript all checked rows even from hidden pages ?
here table header:
<table id="userTable" class="table table-striped table-hover dt-responsive" cellspacing="0">
<thead>
<tr>
<th class="dt-center">
<input name="select_all" value="1" id="example-select-all" type="checkbox" />
</th>
and rows:
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td class="dt-center">
@Html.CheckBoxFor(m => Model[i].Selection)
</td>
in my javascript I did that but get False for rows from hidden pages. for the displayed page the result is correct
$('#btnApprove').click(function (e) {
e.preventDefault();
var rows = table.rows().data();
var isMissingData = false;
var CheckBoxSelection = 0;
for (var i = 0; i < rows.length; i++)
{
if ($('input[name="[' + i + '].Selection"]').is(':checked'))
{
CheckBoxSelection++;
if (rows[i][1] != "")
{
isMissingData = true;
}
}
}
This discussion has been closed.
Answers
any help ?
I'm sure that some already faced that case
Yes, if you search the forum you would find a number of threads on this topic. The problem is that you are using
$('input[name="[' + i + '].Selection"]')
- i.e. a selector that gets data from the document, but DataTables removes rows it doesn't need from the document.Use:
to have it select from the DataTable rows.
Allan
thanks for the answer it help me.
another part of my code was not working because my first column was not the uniq ID.
this plug-in convert the first column ('targets': 0,) in the column definition, to the Checkbox column. this was not clear for me.