is there a way to add working html5 tag on createdRow

is there a way to add working html5 tag on createdRow

psangelovpsangelov Posts: 6Questions: 2Answers: 0

Hello,
I have data data I use coming from ajax in json format, it works fine but the json gives me dates in timestamp and I format them in upon createdRow which works fine, the problem is when I try to search it doesn't search for the value that I have formatted but for the one that comes from my json e.g. if I type 2017 no results are shown, but from part of the timestamp it shows it. I try adding data-search with the formatted date and it adds the attributes but no result are shown in search. Is there a solution for that?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,456Questions: 1Answers: 10,465 Site admin

    Yes, don't format in createdRow since DataTables won't attempt to re-read the data from the DOM (that would be a performance issue).

    Use renderers instead. That also opens up options for orthogonal data.

    Allan

  • psangelovpsangelov Posts: 6Questions: 2Answers: 0

    As I see the renderers are used in the columnDefs but I cannot use them there since I don't know which column will be holding the data I need to convert and I check that data upon row creation and then do the necessary operations. Is there any other way?

  • allanallan Posts: 63,456Questions: 1Answers: 10,465 Site admin

    Orthogonal data is basically the only other option in DataTables.

    However, could you not do the same check in your rendering function and decide there if it needs to be formatted?

    Allan

  • psangelovpsangelov Posts: 6Questions: 2Answers: 0

    I can, but the problem here is that I need to know which column to add that render functionality to and the data is different each time, the column is of different index so it has to be dynamic that is the problem.

  • allanallan Posts: 63,456Questions: 1Answers: 10,465 Site admin

    My point was that you could use the same renderer on multiple columns - have the logic inside it (which I assume you already have for your row created callback) to determine if it needs to reformat the data or not.

    Allan

  • psangelovpsangelov Posts: 6Questions: 2Answers: 0

    If I have defined columnDefs for 15 columns but I have a table that consists of only 10 will be that be a problem?

  • allanallan Posts: 63,456Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Yes. But you can use _all as a target to target all columns (columnDefs.targets).

    Your only other option is to know what the content of the table is before you initialise it.

    Allan

  • psangelovpsangelov Posts: 6Questions: 2Answers: 0

    Thanks a lot! That completely solved my problem. Sorry I've missed _all while reading the documents!

    Best Regards!

This discussion has been closed.