重點: 當數據長度大於20, 只展示前16個字符,后面的用...代替
var table = $("#datatable-buttonss").DataTable({
"aaSorting": [[ 3, "asc" ]],
"search": "全文搜索",
"pageLength": 16, // 每頁展示數量
"lengthMenu": [16, 32, 48],
"displayStart": 0,
// "sPaginationType": "full",
"bJQueryUI" : true,
"sZeroRecords" : "沒有您要搜索的內容",
"bPaginate": true, //翻頁功能
"bInfo": true,//頁腳信息
"bAutoWidth": false,//自動寬度
// "bRetrieve": true,
// "bProcessing": true, //DataTables載入數據時,是否顯示‘進度’提示
// "bServerSide" : true, //是否啟動服務器端數據導入#}
// "bStateSave" : true, //是否打開客戶端狀態記錄功能,此功能在ajax刷新紀錄的時候不會將個性化設
ajax:"/task_mgm/taskDataMine2" + myparas,
"columnDefs":[
{
"targets": [ 0 ],
"Sorting": false,
"width": "5%",
"visible": false
},
{
"targets": [ 1 ],
"Sorting": false,
"render": function ( data, type, row, meta ) {
var order1 = meta.settings._iDisplayStart + meta.row + 1;
var order2 = order1+'、'; // 為每行數據添加索引 如1、 2、 3、 ...
return type === 'display' && data.length > 20 ?
'<span title="'+data+'">'+ data.substr( 0, 16 ) +'...</span>' :order2+data;} // 當數據長度大於20, 只展示前16個字符,后面的用...代替
}, // 給長字符串加省略號
{
"targets": [ 2 ],
"Sorting": false,
"width": "15%",
"render": function (data, type, meta) {
if(data == '非常緊急') {return '<a class="sorting_1" style="background-color: #D94600;">'+ data +'</a>'}
else if(data == '緊急任務') {return '<a class="sorting_1" style="background-color: #F9F900;”'+ data +'</a>'}
else {return '<a class="sorting_1" style="'+ data +'</a>'}
} // 為數據設置不同的背景
},
{"targets": [ 3 ],
"render": function ( data, type, row, meta ) {
var pageType = '?pageType=allPage';
if (type === 'display' && data.length > 20) {
return '<a id="rrrrr" href="/task_mgm/taskinfo_editID=' + row[0] + pageType + '">'+ data.substr(0, 16) + '...</a>'
} // 點擊跳轉的實現
else {
return '<a id="taskFocus" href="/task_mgm/taskinfo_editID='+ row[0] + pageType + '">' + row[1] + '</a>'
}
}
},
{"targets": [ 4 ],
"Sorting": false,
},
{
"targets": [ 5 ],
"width": "28%",
"text-align": "center",
"orderable": false,
// "defaultContent": '<i class="fa fa-edit" id="edit">編輯</i> <i class="fa fa-times" id="delete">刪除</i> <i class="fa fa-star-o" id="focus">關注</i> <i class="fa fa-share-square-o" id="share">分享</i>',
"render": function (data, type, full) {
if(data == 0){return '<i class="fa fa-edit" id="edit">編輯</i> <i class="fa fa-times" id="delete">刪除</i> <i class="fa fa-star-o" id="focus">關注</i> <i class="fa fa-share-square-o" id="share">分享</i>';}
else {return '<i class="fa fa-edit" id="edit">編輯</i> <i class="fa fa-times" id="delete">刪除</i> <i class="fa fa-star" id="focus">已關注</i> <i class="fa fa-share-square-o" id="share">分享</i>';} } }, ],});