Column data is a function, server side gets "function" as column name
Column data is a function, server side gets "function" as column name
I have a column with a data value based on a function. Something like this,
data: (row, type, set, meta) => {
return '1';
}
I receive the data request server-side but the column definition contains Text: 'function'.
I understand why I'm getting this, which is because I haven't specified a field name, I've given it a function. The field name would normally be returned by the data field,
data: 'myDataFieldName',
The question is, is there another way to specify the field name that would make it return the correct field name instead of the word 'function'?
This question has an accepted answers - jump to answer
Answers
columns.data
can be a function, see here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.Cheers,
Colin
Hi Colin, yeah, I have it as a function, but when the data is coming from server-side, and you try to order by the column that has the data:function defined, it errors saying field name is "function".
Unfortunately, this is an intranet site in pre-production so I can't provide a link, and because it requires a server-side feed, I can't update your example
I may be misunderstanding your question, but do you mean like this, using the 'title' parameter?
Sorry, I'm still not following. This example here has
serverSide
, and is using a function. Could you modify that to demonstrate the issue, please,Colin
I think the question is around the request parameters, specifically this:
Where
data
isfunction
.Maybe you can use
columns.data
with the desired field name and usecolumns.render
to display what you want. Another option is to usecolumns.orderable
to disable ordering of that column.What do you want the server script to do with that column when you use
columns.data
as a function.Kevin
Server-side needs that column name to build the SQL order by clause. What field from the request do you use server-side to do the ordering?
Server-side, I'm getting this in the request payload when I order by that column,
And column 12 in the column data is,
The client specifies
order
in the request. The protocol is discussed here. Also see examples here.Cheers,
Colin
So the intention is to order by column index and not by column name?
Yep, that's correct - this thread discusses using names,
Colin
Thanks for your help, colin. I have a working solution now