更改jquery数据表aoColumns [英] Altering jquery datatables aoColumns
问题描述
但是,由于表格的数量和类型可能会更改,应该保持易于维护。
现在的问题是直接使用相同的构造函数。
我可以将aoColumns设置为参数,还不能在运行时重新设置?
现在,代码如下:
tables = $(。dat)。dataTable({
bJQueryUI:true,
bDeferRender :true,
bPaginate:false,
bProcessing:true,
sAjaxSource:ajaxdataA.json,
ssAjaxDataProp:data
aoColumns:[{mData:col1},{mData:col2},{mData:col3}]
});
我想将其设置为数组,然后为个人使用sAjaxSource和aoDataColumns的细节表。
当然也可以通过存储参数对象并扩展它或使用工厂闭包来实现。
我也考虑使用AngularJS。
有人有更优雅的解决方案吗?
我想你可以使用 aoColumnDef
而不是使用 aoColumns
。 p>
aoColumnDef 甚至可以读取列中的一些css类,以更加动态的方式配置DataTables。
查看其文档: http://www.datatables.net/usage/columns
I am using uptil now 3 datatables in jquery-ui tabs. i prefer to keep them all in background and really use 3 tables. The data comes via ajax in arrays of objects (is used in that format also by other presenters).
However, since the number and type of tables could change and should be kept easy to maintain.
The problem now is to elegently use the same constructor. Can I set the aoColumns as a parameter only and not also re-set it at runtime?
Right now, the Code looks like this:
tables=$(".dat").dataTable({
"bJQueryUI": true,
"bDeferRender": true,
"bPaginate": false,
"bProcessing": true,
"sAjaxSource": "ajaxdataA.json",
"ssAjaxDataProp" : "data",
"aoColumns": [{"mData": "col1"}, {"mData": "col2"},{"mData": "col3"}]
});
I would like to set that as an array and then use specifics for the sAjaxSource and aoDataColumns for the individual tables. It could of course also be achieved by storing the parameter object and extending it or using a factory closure. I also thought on using AngularJS instead.
Does anybody have a more elegant solution?
I think you can use the aoColumnDef
instead of using aoColumns
.
aoColumnDef can even read some css classes in your columns to configure DataTables in a more dynamic way.
Take a look at its documentation: http://www.datatables.net/usage/columns
这篇关于更改jquery数据表aoColumns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!