h0ru5
h0ru5

Reputation: 517

Altering jquery datatables aoColumns

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?

Upvotes: 4

Views: 35205

Answers (1)

Romias
Romias

Reputation: 14133

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

Upvotes: 4

Related Questions