我正在尝试使用Jquery的Datatable插件创建一个完全可修改的数据表。通过完全可修改的表,我的意思是用户将能够编辑,删除,更新,添加表上的列。基于这些示例,目前我正在尝试以下javascript代码:
function var_dump(obj) {
if(typeof obj == "object") {
return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
} else {
return "Type: "+typeof(obj)+"\nValue: "+obj;
}
}//end function var_dump
var oTable;
var giRedraw = false;
var giCount=11;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
var iRow = oTable.fnGetPosition( anSelected[0] );
oTable.fnDeleteRow( iRow );
} );
oTable = $('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "lib/server_processing.php",
"fnDrawCallback": function () {
$('#example tbody td').editable( 'lib/editable_ajax.php', {
"callback": function( sValue, y ) {
alert(sValue);
/* Redraw the table from the new data on the server */
oTable.fnDraw();
},
"height": "14px"
} );
}
} );
} );
function fnClickAddRow() {
oTable.fnAddData( [
giCount+".1",
giCount+".2",
giCount+".3",
giCount+".4",
giCount+".5", ]
);
giCount++;
}
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i<aTrs.length ; i++ )
{
if ( $(aTrs[i]).hasClass('row_selected') )
{
aReturn.push( aTrs[i] );
}
}
return aReturn;
}
这在用户界面中工作正常,但我不知道如何将列信息发送到服务器端。好的,我可以将列的新值发送到server_ajax脚本,但是如何发送有关列的其他相关信息,如数据库中已编辑列的唯一ID。
答案 0 :(得分:0)
如果您想在这里使用DataTables,那么文章将展示如何使用JQuery DataTables http://www.codeproject.com/KB/aspnet/MVC-CRUD-DataTable.aspx实现CRUD功能 所有必要的功能都放在jquery.datatables.editable.js插件中,该插件在DataTables插件之上添加了CRUD功能。
答案 1 :(得分:-1)