我的网页中有一个数据表,其中包含一页以上的分页数据。根据datatables 给出的示例,我使用以下 javascript/jQuery 提交表单:
<script>
var oTable;
$(document).ready(function() {
$('#form').submit( function() {
var sData = oTable.$('input').serialize();
$.post('', sData); // WORKS
// $.post('', sData, $('body').html(data)); // DOES NOT WORK
return false;
} );
oTable = $('#meters').dataTable();
} );
</script>
当我通过 发布时$.post('', sData);
,我的所有表格行都已发布。当我使用 发布时$.post('', sData, $('body').html(data));
,仅发布表格可见页面的行。为什么?
我对 jQuery 还很陌生——也许我遗漏了一些东西……
这是我用来初始化表的代码:
<script>
/* Create an array with the values of all the input boxes in a column */
$.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+') input:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.value );
} );
return aData;
}
/* Create an array with the values of all the select options in a column */
$.fn.dataTableExt.afnSortData['dom-select'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+') select:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( $(this).val() );
} );
return aData;
}
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+') input:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.checked==true ? "1" : "0" );
} );
return aData;
}
$(document).ready(function() {
$('#meters').dataTable(
{
"aoColumns": [
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-select" },
{ "sSortDataType": "dom-checkbox" },
],
"aoColumnDefs": [
{
"aTargets": ["vbNoSearchSort"],
"bSearchable": false,
"bSortable": false
}
],
"bProcessing" :true,
"bStateSave" :true,
"sPaginationType": "full_numbers"
}
);
} );
</script>