Próbuję utworzyć funkcję, która sprawdza wszystkie pola wyboru w DataTable, w tym ukryte wiersze. Oto kod html do "wyboru" kolumny:sprawdza wszystkie pola wyboru w DataTable, w tym ukryte wiersze.
<div class="usersTable" id="userTable">
<table cellpadding="0" cellspacing="0" id="customersList" >
<thead>
<tr>
<th><input type="checkbox" name="selectall" id="selectall" class="selectall"/></th>
<th width="200">val1</th>
<th width="80px">val2</th>
<th width="70px">val3</th>
<th width="450">val4</th>
<th width="60px">val5</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
Umieść przycisk:
<input type='button' value='select all' id='selectallboxes' name='selectallboxes' />
I kod JQuery że nie działa:
$(function() {
otable = $('#customersList').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aLengthMenu" : [ [10,20,50,100,1000], [10,20,50,100,1000] ],
"iDisplayLength": 100,
"bProcessing": true,
"bServerSide": true,
"aaSorting":[],
"iDisplayStart": 0,
"sAjaxSource": "filename",
....
$("#selectallboxes").click (function() {
alert(dt.fnGetNodes().length + ' is total number')
var selected = new Array();
$('input', dt.fnGetNodes()).each(function() {
$(this).attr('checked','checked');
selected.push($(this).val());
});
// convert to a string
var mystring = selected.length;
alert(mystring);
})
Co się stanie, jeśli zmienisz '$ (" # selectallboxes ") .Kliknij" do "$ (" # selectall "). – darshanags
@darshangs To by utworzyło zdarzenie click tylko dla faktycznych pól wyboru, nie dla przycisku wyboru wszystkich, problemem jest logika zdarzenia click, a nie handlerka –
@DavidBarker Mój błąd. Czytałem to pytanie niepoprawnie. – darshanags