Supply unique column identifiers

Supply unique column identifiers

flip101flip101 Posts: 1Questions: 0Answers: 0
edited January 2014 in Feature requests
== Current working ==
I'm using the Reorder plugin. In side the fnReorderCallback() callback i check the ordering with this.fnOrder(). Then i get a list back of unique identifiers 0-indexed. Suppose i have a table like:

[code]Country, Capital, Language[/code]

then

[code]Country = 0;
Capital = 1;
Language = 2;[/code]


== Request ==
Right now i save the column order in my database and they are indexed by a primary key. I would like to pass this primary key to the client when loading the data with AJAX. I took a look at the code of fnOrder() and it seems to be using the aoColumns variable. I also use the aoColumns variable to load the column headers, so this makes sense.

The ordering is only one use case for passing column ID's to the server. Another very important one is if you want to script mouseclicks or other events to the column and then send it to the server.

In short i would like to pass additional information into the aoColumns which i can then read with fnOrder (or an alternative function).

While the current implementation does cover all use cases (with server-side book-keeping in place) it can be improved. Not only would this more convenient and clear, i would also have to worry less about keeping client side and server side state in sync. I find it incredibly difficult to map out the scenario's of what could happen if a request has a timeout and the possiblities of a state mismatch occuring.


== Extra: extended problem description ==
In the initial state the server knows the column ordering: 0, 1, 2
So each column needs this number as identifier (to map the datatables to primary key).
In addition it needs a number to identify the ordering.

- Initial data load
[code]ID DataTables_ID Order
23 0 0
10 1 1
67 2 2[/code]

- Order action occurs: column 1 (0 index) and 2 (1 index) swap
[code]ID DataTables_ID Order
23 0 1
10 1 0
67 2 2[/code]

- DataTable is reloaded, the previous order will be the new DataTables_IDs
[code]ID DataTables_ID Order
23 1 1
10 0 0
67 2 2[/code]

This last step is extra bookkeeping on the server-side because DataTables resets the order again everytime new data is loaded.


== Extra 2: use case 2: RESTfull API's
When writing a clean RESTFull API, you usually send only the model ID with the model properties to the server. Since the model ID is not available it has to do a lookup in the database to map the DataTables_ID back to the primary key. But when you have one table to hold columns in different tables (One Table to Many Columns) additional information has to be passed (namely the Table ID). Now you can no longer send your model to the server on itself, but you have to include other parts of your data structure.
This discussion has been closed.