Server-side processing, "render" functions, and nested data
Server-side processing, "render" functions, and nested data

Hi everyone,
I have a table where one column is linking to an object (my debugger code): azesed:
{ "name": "Response.Jhn", "data": "Response", "render": $.fn.DataTable.render.jhn(), "orderable": false }
I want to do some operation on this column and display data depending on a child member of Response
, so I wrote the render
function here ($.fn.DataTable.render.jhn()
):
$.fn.dataTable.render.jhn = function() {
return function(data, type, row) {
if (type === "display") {
if (data === null) return "Not priced";
if (data.Jhn == null) {
return "Not issued";
} else {
return "JHN-" + data.Jhn;
}
} else {
if (data === null) return "Not priced";
if (data.Jhn == null) {
return "Not issued";
} else {
return data.Jhn;
}
}
}
}
I am using server side processing (not sure it really matters here) and individual column dropdowns as in the example here:
https://datatables.net/examples/api/multi_filter_select.html
I removed the escaping so here is my implementation:
var select =
$('<select class="form-control"><option value=""></option></select>')
.appendTo($(column.footer()).empty())
.on('change',
function() {
column
search(this.value)
.draw();
debugger;
});
But the issue is for this particular column when I search it, I always get [object Object]
in return instead of the code I thought I specified in the renderer ("Not priced, "Not issued" or data.Jhn
)
How do I specify the correct data in the renderer? Or maybe I am getting the filter wrong?
Thanks for the help! And I love the plug-in!
This question has an accepted answers - jump to answer
Answers
Silly mistake. When I was populating the filter I forgot to call the render function to put the appropriate data in the
value
tag of the<select>
. I was putting in the object itself, not its child properties.Thanks for posting back. Good to hear you've got it working now!
Allan