If cell value, show text instead of value, but still use value for the backend?
If cell value, show text instead of value, but still use value for the backend?
I'm having a little trouble in figuring out where this logic needs to go and how to do it properly. I have date columns in my table, but if a date matches a certain string, I would like to show specific text instead of the date, but still use the date for everything else, such as sorting etc. How do I go about in doing it?
My table initialization: https://jsfiddle.net/p9z17btg/
My data source is just a mapping of a multidimensional array that returns complete objects. I can't throw my conditional logic there because that will change the actual value before the table gets it.
My condition is basically if (cellValue = '01-01-01') then (cellText = 'TBD').
The reason why this is an issue is because before I was spitting out dates that have TBD, but this can't be sorted, so I had to give it a date, but now I want to re-show TBD to the user. I am using the moment.js plugin to sort.
Answers
I ended up doing something like this:
var cells = table.cells( ":contains('01-01-01')" ).nodes();
$(cells).text('TBD');
I don't know if that's the best way of doing it, but oh well.
My solution gives me another question, what's the syntax for all nodes in a given column that contains?
This doesn't work plus the variations I've tried:
var cells2 = table.column(18).cells(":contains('01-01-01')").nodes();
[EDIT]
OK a little more progress, I have :
var cells2 = table.cells(0,18,":contains('01-01-01')").nodes();
But 0 specifies row 0, how do I specify all rows?
After looking at the docs again, row and column are not optional, they both have to be present, so I guess I can't use the cells() method. What should I do?
There's a render option that will allow you to render a different value on the dom then what's in the dataTable memory.
https://datatables.net/examples/advanced_init/column_render.html
So you could write a render function for if data = '01-01-01' return "TBD"