('input:checked').length not working across pages
('input:checked').length not working across pages
khaos
Posts: 47Questions: 11Answers: 0
desired: At least one checkbox must must be checked to enable the button.
This works fine on each individual page. I am using fnDrawCallback to restart the .click for all the checkboxes. But I don't know how to get the real ('input:checked').length.
[code] $(document).ready(function () {
SetButtonBasedOnChecks();
$('.addme').click(function () {
SetButtonBasedOnChecks();
});
});
function SetButtonBasedOnChecks() {
var $btn = $('.notempty');
if ($('input:checked').length > 0) {
$btn.removeAttr('disabled');
} else {
$btn.attr('disabled', 'disabled');
}
} [/code]
the DataTable code:
[code]
var oTable = $('#<%= gvTest.ClientID %>').dataTable({
"bJQueryUI": true
, "bStateSave": false
, "sPaginationType": "full_numbers"
, "aoColumns": [
{ "sSortDataType": "dom-checkbox" }
, { "sSortDataType": "dom-text", "sType": "numeric" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
]
, "fnDrawCallback": function() {
//alert( 'DataTables has redrawn the table' );
SetButtonBasedOnChecks();
$('.addme').click(function () {
SetButtonBasedOnChecks();
});
}
});[/code]
This works fine on each individual page. I am using fnDrawCallback to restart the .click for all the checkboxes. But I don't know how to get the real ('input:checked').length.
[code] $(document).ready(function () {
SetButtonBasedOnChecks();
$('.addme').click(function () {
SetButtonBasedOnChecks();
});
});
function SetButtonBasedOnChecks() {
var $btn = $('.notempty');
if ($('input:checked').length > 0) {
$btn.removeAttr('disabled');
} else {
$btn.attr('disabled', 'disabled');
}
} [/code]
the DataTable code:
[code]
var oTable = $('#<%= gvTest.ClientID %>').dataTable({
"bJQueryUI": true
, "bStateSave": false
, "sPaginationType": "full_numbers"
, "aoColumns": [
{ "sSortDataType": "dom-checkbox" }
, { "sSortDataType": "dom-text", "sType": "numeric" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
, { "sSortDataType": "dom-text" }
]
, "fnDrawCallback": function() {
//alert( 'DataTables has redrawn the table' );
SetButtonBasedOnChecks();
$('.addme').click(function () {
SetButtonBasedOnChecks();
});
}
});[/code]
This discussion has been closed.
Replies
[code]
if ($('input:checked', oTable.fnGetNodes()).length > 0) {
[/code]
The reason for this is that the TR elements which are needed for a given page are removed from the DOM - hence the need to use the API to get an array of the full list :-)
Allan
In order to get it to work I had to parenthesize the selector. No big but it took me a few minutes to wake up and smell the coffee.
[code] if (($('input:checked', oTable.fnGetNodes())).length > 0) { [/code]
Allan