Jquery Datatables的使用详解

2020-05-29 07:26:34易采站长站整理

}
},
{ "data": "recordsbegindate","orderable": false },
{ "data": "recordsenddate" ,"orderable": false},
{ "data": "uploadsoundsids","orderable": false },
{"render":function ( data, type, row, meta )
{

var operationId = row.operationid;
return "<button type="button"οnclick="deleteOperation("+ operationId +"," +meta.row+ ")">删除</button>";
}}
];

可以看到,将后端给前端返回的出参,使用属性名依次绑定到列上,orderatble是说明这一列是否支持排序。render可以定义一个function也可以定义成其他属性,是用来转换数据的,比如返回的时间是一个时间戳,但是我要现实的是一个fomat的时间,就可以在render中转换。还有最后一行,我想在最后一列添加一个删除按钮,那这个删除按钮就可在这里通过数据的唯一索引来动态生成。

看下官方对render中使用function定义的说明:

function render( data, type, row, meta )

Description:

If a function is given, it will be executed whenever DataTables needs to get the data for a cell in the column. Note that this function might be called multiple times, as DataTables will call it for the different data types that it needs – sorting, filtering and display.

Parameters:

NameTypeOptional
1data

Any

No

The data for the cell (based on columns.data)

2type

string

No

The type call data requested. This is used for DataTables’ orthogonal data support. This value will be one of:

filter: Get the value that DataTables should use for filtering on this cell.
display: The value to display in the table.
type: Value to use for type detection. This should normally match the sort value – see type detection plug-in documentation.
sort: Get the data to use for sorting on this cell – the value returned should typically be numeric or a string, but custom plug-ins can be used – see the plug-in documentation. Note that this value is sort for legacy reasons (rather than being order which would be more consistent with the rest of the API).
undefined: Get the original data for the cell (i.e. unmodified).
Custom value: It is possible for plug-ins such as Responsive (through its responsive.orthogonal option) and Buttons (buttons.exportData()) to request custom data types specified by the developer. This can be useful in cases where you want send certain data to a particular extension.

See also the cell().render() method which can be used to execute the given rendering method at any arbitrary time.

3row

Any

No

The full data source for the row (not based on columns.data)