Display different value than actual data source value
Display different value than actual data source value
enjoypb
Posts: 31Questions: 12Answers: 0
Is there a way to display a different value than the source data in my cell?
My data source is ajax:json and I'm displaying the tables great. I just have one column with about 6 different values that I need to display as more readable values.
For instance I want to display:
'Dog' whenever the value of a cell is 'puppy', or
'Cat' if the value is 'kitten'.
Thanks!
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Use a "render" function.
https://datatables.net/manual/data/renderers#Data-rendering
Thanks tangerine. I've spent another couple hours on this and am butting my head on the wall. Here's what I've been trying (along with 100 different variations). I keep getting the datatables.net/tn/4 message but, can't find what I'm doing wrong. There may be null values (empty values) so I'm not sure if that's affecting this.
Here's my latest iteration:
Do you see where I'm going wrong? Thanks again.
You need to return a value to display. For example:
Hope the syntax is right but should give you the idea.
Kevin
Awesome thank you kthorngren. I was successful with the following. I am getting a chrome error popup for a specific datatables row but, have checked my data and cannot find the flaw (every record has one of the six labels). I get that error with or without the last row active. Just off hand do you know if it's possible to go to a specific row of data that datatables is reflecting in that error?
Thanks again. Here's what worked:
What does it say?
Also
you probably want to fix that line.
Hey thanks for the heads up on the typo Tangerine.
I found the error is referring to empty fields. I tried the else/if with null or empty but, still get the error. Am I doing that correctly (if the above example were uncommented)?
Thanks!
I would try making it just a
return ''
. That way it will return something if none of the if's match.Kevin
Ok cool. Thank you both very much.
whats about show diferent data from database, not diferent value
like
if (data == 'onsale_c') { return { "data": "Name" },}
can anyone help me?
@Imam Trizna - I replied to this on your thread here.