Decoupling data from display

Decoupling data from display

JamesLaiJamesLai Posts: 6Questions: 0Answers: 0
edited August 2010 in General
What is the best way to decouple data (from a Javascript array or an Ajax source) from the display? The reason is I often deal with arrays which contain more data than actual columns I want to display - often the table I display in the end has very little (structure wise) with the data I'm actually sending.

For example, a column which displays a link and a name of that link technically takes 2 variables from the data array, the URL and the name of that link you want to display. Or I might provide an unique ID number for the row for subsequent links (ie: Edit), along with other links like Delete, etc. Obviously in this scenario, the data I send over the wire has very little to do with how I display the table.

Right now I basically am forced to use the aoColumns object and constantly use fnRender to pull whatever data I need, though that aoColumns object has to equal the same length as my data source. Is there a better way to be doing all this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What you can do is use fnServerData to "intercept" the json from the server and alter it into whatever format of array you want to pass to DataTables. For example here is a plug-in which takes OpenSearch API results and converts them into a 2D array: http://datatables.net/plug-ins/server-data-formats#OpenSearch

    Allan
This discussion has been closed.