Server Data, JSON ok, but what about XML?

Server Data, JSON ok, but what about XML?

jonatecjonatec Posts: 3Questions: 0Answers: 0
edited September 2010 in General
Hi

When using DataTables, is JSON the only data format supported, can I return XML from the server and process that into DataTables?

Thanks....

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You certainly can used XML from the server-side, although it will require a transform into a 2D Javascript array on the client-side. In this way, any XML format you want can be used, just use (write) a suitable small script to take the XML and convert it into a plain 2D array, which can then be used by DataTables core.

    There is a plug-in page for this ( http://datatables.net/plug-ins/server-data-formats ) although only one format publicly available just now. It will give you an idea of how to go about it thought.

    Allan
  • jonatecjonatec Posts: 3Questions: 0Answers: 0
    Thanks for that. Would a work-around be to return xml using standard jQuery, populate a hidden table, then is it possible to populate DataTables with the dynamically populated html table ? Would that work ?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited September 2010
    Yes that would work - but I suspect it would be more work that to just parse through the XML creating a 2D array - and longer to execute.

    If it just an XHTML table you are returning? A loop over each TR and then each TD would do the trick nicely.

    Allan
  • jonatecjonatec Posts: 3Questions: 0Answers: 0
    Brill. Cheers for that...
This discussion has been closed.