nie*_*lsv 2 javascript php ajax jquery datatables
我有一个带有 ajax 调用的数据表。我像这样形成表格:
var _initTable = function() {
$('#datatables tr').not(':first').on('click', function() {
var dateandtime = $(this).find(':nth-child(3)').text();
window.location.href = '/results/detail/dateandtime/' + dateandtime;
});
};
$('#datatables').dataTable({
bProcessing : true,
sProcessing : true,
bServerSide : true,
sAjaxSource : '/results/load-results',
fnServerParams: function ( aoData ) {
aoData.push( {"name": "quizid", "value": quizid },{ "name": "questionid", "value": questionid } );
},
aoColumnDefs : [{'bSortable' : false, 'aTargets' : ['no-sort']}], // make the actions column unsortable
sPaginationType : 'full_numbers',
fnDrawCallback : function(oSettings) {
_initTable();
}
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我向我的 php 操作发送了 2 个参数。
现在我想在单击按钮时重新加载表格。所以我想要做的是再次调用ajax并发送其他参数(quizid会相同,但questionid会不同)。
我知道你有这样的东西,oTable.fnReloadAjax(newUrl);但我应该在 newUrl 参数中粘贴什么?
我做了一个 jsfiddle:http : //jsfiddle.net/8TwS7/
您应该能够通过使用 fnServerData 而不是 fnServerParams 来完成此操作
var oTable = $('#datatables').dataTable({
bProcessing : true,
sProcessing : true,
bServerSide : true,
sAjaxSource : '/results/load-results',
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "name": "quizid", "value": quizid } );
aoData.push( { "name": "question_id", "value": question_id } );
$.getJSON( sSource, aoData, function () {
/* Do whatever additional processing you want on the callback, then tell DataTables */
}).done(function(json){
fnCallback(json);
}).fail(function(xhr, err){
var responseTitle= $(xhr.responseText).filter('title').get(0);
alert($(responseTitle).text() + "\n" + formatErrorMessage(xhr, err) );
});
},
});
Run Code Online (Sandbox Code Playgroud)
然后你应该能够调用一个点击函数来重绘你的表,使用 fnDraw API 调用我们在数据表初始化时创建的变量没有问题
$('#somelement').on('click', function(){
oTable.fnDraw();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19082 次 |
| 最近记录: |