Render function not being called
Render function not being called
msavard
Posts: 6Questions: 3Answers: 0
I cannot get the render function to be called on my datatable. The data source is an AJAX call and the data comes in fine. But I want to add a link to one of the fields so I am using a render function on that column to build the link.
Here is the pertinent code:
"ajax":{
"url":"ajaxtest.cfc?method=getData",
"dataSrc": "DATA",
"columns": [
{"DATA":"ROLLYEAR"},
{"DATA":"APN",
"render": function (data){
if (data !== null){
return "<a href='pagelink.cfm?id="+data+"'>"+apn+"</a>";
} else {
return "<a href='pagelink.cfm?id="+data+"'>"+apn+"</a>";
}
}},
{"DATA":"ARCNUMBER", "render":"test"},
{"DATA":"APPRAISER"},
{"DATA":"ARCGENERATEDDATE"},
{"DATA":"STATUS"},
{"DATA":"APPROVEDBY"},
{"DATA":"CALAMITYTYPE"},
{"DATA":"DIST"},
{"DATA":"NGH"},
{"DATA":"CL"}
]
}
No matter what I try the APN column is always generated as is with no link. I've even tried putting a console.log in the render function and get no output to the console. I've tried making the render function something simple like outputting a different text string and still it doesn't work. The data being returned looks like this:
{"COLUMNS":["ROLLYEAR","APN","ARCNUMBER","APPRAISER","ARCGENERATEDDATE","STATUS","APPROVEDBY","CALAMITYTYPE","DIST","NGH","CL","ID","ARCID"],"DATA":[[####,"XXXXX",####,###,"XXXX-XX-XX","XXXX","XXXXX","XXXXX",###.#,###,null,####,####]]}
(I've replaced the data with ### for numbers and XXXX for text fields as the data is a bit sensitive.)
I've tried the more complete render function that looks like this: "render":function (data, type, row,meta) but that doesn't make any difference either.
Any ideas? I'm at my wits end. I have read many queries on similar issues and I can't get any of those solutions to work here though it looks like it should. I'm sure I'm missing something obvious.
Thanks for any help.
This question has an accepted answers - jump to answer
Answers
There are two issues:
columnsoption is inside theajaxoption. Move it outside the ajax option.columns.dataoption you defined won't work and should result in the dreadedRequested unknown parametererror. You can either change your data response to an array of objects or simply not use thecolumnsoption. Currently you aren't using the columns option since its inside the ajax option.Instead of using the columns option you would use
columnDefsfor your render function withtargets: 1. Then the render function should run.Kevin
You have just made my life so much better today.
Thanks! That did it.