最近使用datatable時,發現沒有像jqgrid那樣生成序號列,在國外網站搜羅了一下還是很簡單的,就要在aoColumns中添加一空列占位就行,然后再用fnRowCallback添加序號
示例如下 by hsuchan:
//加載列表數據 tables = $('#launch_table').alijkDataTable({ "sAjaxSource" : path+'/appUseStatistics/appLaunchDetail.do?'+params, "iDisplayStart" : 0, "iDisplayLength" : 10,//每頁顯示10條記錄 "bSort":false,//關閉排序 "order": [[ 1, 'asc' ]], "bAutoWidth":true, //列的寬度會根據table的寬度自適應 "aoColumns" :[ {"sClass" : "center", "mDataProp" : ""},//序號列--空 {"sClass" : "center", "mDataProp" : "COMPANY_NAME"}, {"sClass" : "center", "mDataProp" : "PAY_EXPIRES_IN"} ], "fnRowCallback" : function(nRow, aData, iDisplayIndex){ $("td:first", nRow).html(iDisplayIndex +1);//設置序號位於第一列,並順次加一 return nRow; } });
轉載請注明出處,謝謝。