Remembering Checkbox Values On Submit
Remembering Checkbox Values On Submit
Alan, congrats on a great script! It's perfect for my requirements.
I have a table that is populated with invoice data.
I've populated the 3rd column with a checkbox when a particular invoice is eligible for payment. The user may need to check one or more on each page. Then, they'd click a button to proceed to the payment page.
The problem is this: the checked checkboxes are only being remembered on the final page before the payment button is clicked.
In searching the forums it seems that I should be using fnDrawCallback. However, the various implementations I'm seeing in the forums are much more complex than my requirements. So I'm having trouble extracting the pieces I need.
Here is my basic implementation as it stands:
[code]
jQuery(document).ready(function() {
jQuery('#example').dataTable( {
"bJQueryUI": true,
"aaSorting": [[0,'desc']],
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sPaginationType": "full_numbers",
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
{ "sType": 'date' },
{ "sType": 'currency' },
{ "sType": 'currency' },
null
]
});
});
[/code]
I have a table that is populated with invoice data.
I've populated the 3rd column with a checkbox when a particular invoice is eligible for payment. The user may need to check one or more on each page. Then, they'd click a button to proceed to the payment page.
The problem is this: the checked checkboxes are only being remembered on the final page before the payment button is clicked.
In searching the forums it seems that I should be using fnDrawCallback. However, the various implementations I'm seeing in the forums are much more complex than my requirements. So I'm having trouble extracting the pieces I need.
Here is my basic implementation as it stands:
[code]
jQuery(document).ready(function() {
jQuery('#example').dataTable( {
"bJQueryUI": true,
"aaSorting": [[0,'desc']],
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sPaginationType": "full_numbers",
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
{ "sType": 'date' },
{ "sType": 'currency' },
{ "sType": 'currency' },
null
]
});
});
[/code]
This discussion has been closed.
Replies
Allan
Allan
You asked:
"When you say that they are only being remembered for the last page, do you mean that the checkbox names for the page which is visible are the ones which are known (i.e. The ones submitted to the server, or are in the DOM)? "
Answer: The ones in the DOM.
The example you provided was helpful. This is what my current implementation now looks like with the example integrated:
[code]var oTable;
jQuery(document).ready(function() {
jQuery('#InvoiceDetail').submit( function() {
var sData = jQuery('input', oTable.fnGetNodes()).serialize();
alert( "The following data would have been submitted to the server: \n\n"+sData );
return false;
});
oTable = jQuery('#example').dataTable( {
"bJQueryUI": true,
"aaSorting": [[0,'desc']],
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sPaginationType": "full_numbers",
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
{ "sType": 'date' },
{ "sType": 'currency' },
{ "sType": 'currency' },
null
]
});
});
[/code]
With this code, I've verified that all of the checked values are now submitting. So, that's good.
What I'm trying to do now is return those values on a separate page onsubmit to notify the user that they're about to pay "x" invoices. Unfortunately, I'm still only returning the last checked values that were in the DOM on the previous page.
Any ideas?
Thanks.
Allan
Sorry, I probably wasn't specific about what 'x' is. 'X' is actually the invoice number and $ value. In any event, it's still just a DOM query.
I tried using $('input:checked') instead of simply $('input'). Same problem. I'm still not getting all of my checkbox values to post properly - just those on the last page after clicking through the pagination.
Allan
Yes, I'm using oTable.fnGetNodes(). Here is my current initialization code:
[code]var oTable;
jQuery(document).ready(function() {
jQuery('#InvoiceDetail').submit( function() {
var sData = jQuery('input:checked', oTable.fnGetNodes()).serialize();
alert( "The following data would have been submitted to the server: \n\n"+sData );
return true;
});
oTable = jQuery('#example').dataTable( {
"bJQueryUI": true,
"aaSorting": [[0,'desc']],
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sPaginationType": "full_numbers",
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
{ "sType": 'date' },
{ "sType": 'currency' },
{ "sType": 'currency' },
null
]
});
});[/code]
Thanks for your time.
Allan
Allan