Is it possible to add metadata to ajax loaded data?

Is it possible to add metadata to ajax loaded data?

ladislav2ladislav2 Posts: 13Questions: 0Answers: 0
edited October 2013 in General
Hi,

one thing that I do not know how to resolve by some better means, is that I cannot add some metadata to the every cell of aaData got from fnReloadAjax call.

1) Some cells need to be colorized and decision (rule if it has to be colorized and color) is made by the server. So what I'm doing is that I sent data in aaData of every cell in the form color|celldata and I parse it in mRender function. But this is very awkward..

2) Also I want to add dropdown menu in every row. Links in this menu have to be generated somehow, so I will send urls in aaData and parse it.

Is there some other way how to do it? It would be nice to have possibility to set maybe some data attribute to every cell/row in aaData. I assume that sending markup in aaData is not recommended or supported.

EDIT: some nested json?

Thanks for any hint

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'd use objects in your JSON personally - then its easy to include any data you want. See this blog post for using objects with DataTables: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
  • ladislav2ladislav2 Posts: 13Questions: 0Answers: 0
    edited November 2013
    I returned back to this problem. It actually works. I send in aaData JSON objects and then in aoColumnDefs I have it defined as below, the problem is, these fields are not searchable at all. If I type anything in Search box, it always returns an empty set. Should I somehow tell to the searching algorithm to search in .value property of aaData objects?

    EDIT: Sorting does not work as well.

    Thank you for any hint.

    [code]
    "fnCreatedCell": function(nTD,sData,oData,iRow,iCol) {
    if (sData.color != "") {
    var color = sData.color
    $(nTD).css('background-color', color);
    }

    $(nTD).html (sData.value)
    }
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    We'd need a link to a test case to know why the search isn't working.

    Allan
  • ladislav2ladislav2 Posts: 13Questions: 0Answers: 0
    Please see http://jane.brilant.sk/datatable-test/
  • ladislav2ladislav2 Posts: 13Questions: 0Answers: 0
    Any hint?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You mData options refer only to an object - i.e. `fromname` is an object in the JSON data. So DataTabels doesn't know what you would want to filter or sort on - it can't filter on an object. You'd use something like `fromname.color` .

    Allan
  • ladislav2ladislav2 Posts: 13Questions: 0Answers: 0
    This works, but if I use .value in mData options it does not pass the object in fnCreatedCell so I do not have the colour property there available and I cannot colorize the cell.. (see test case). Maybe the whole approach is not that good..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The third parameter of fnCreatedCell gives you the data for the whole row - so could you use that? The other option is to use mRender to pull out the data you want for rendering: http://datatables.net/blog/Orthogonal_data

    Allan
This discussion has been closed.