row().id() null handling
row().id() null handling

Hello,
Referring to documentation: row().id()
It states:
If the row does not have an id available
undefined
will be returned
I intentionally have some rows with null
DT_RowId. I want to set the field 'dir_ID' to null
. I have used the code below:
// Append a folder
$('#adminDt').on('click', 'button.editorAppend', function (e) {
e.preventDefault();
console.log(table.row($(this).closest('tr')).id())
editor.field('dir_ID').def( table.row($(this).closest('tr')).id() )
editor.create( {
title: 'Append directory',
buttons: 'Append'
} )
} )
Unexpectedly I get null
though the docs suggest undefined
should be returned.
The result is that null
is sent to the server, which is undesirable.
I would like to send null
to the server.
Any advice appreciated!
Steve
This question has an accepted answers - jump to answer
Answers
A workaround is to use DT_RowId accessed from
row().data()
DT_RowId provides a genuine
null
instead of"null"
orundefined
Should
row().id()
providenull
?I think what that is saying is if Datatables doesn't have a column used is the row ID then it will return
undefined
. As shown in this example:http://live.datatables.net/wobakude/1/edit
However if you have a column identified as the row ID then it will return the value in the column. If you have
null
instead ofnull
in the data then that is what will be returned. You could investigate what happens to thenull
value from the DB and why Datataables has it asnull
. My guess is the JSON parser in your server is converting it.Kevin
Thank you Kevin and for the live example demonstrating
undefined
.I'm unsure why the following results in
null
(in console)While the following (based on same data) results in
null
(in console)Given the two results are different in console on the client, I don't think it's a server issue.
But I do have a way forward :-) Thank Kevin
I think you are right. I believe it has to do with automatic type detection as described in
columns.type
. The default type is string. I think that is what happens to thenull
is it gets converted to a string by the type detection process.Kevin