How to render read only Editor field
How to render read only Editor field
Hi all,
i am currently implementing read only fields on my DataTable with inline edit enabled. My problem is that i cant find a way to render the values for inline edit. Columns have an attribute called render where you can call a function to render the value. I am currently missing the same for the editor inline edit fields. Is there a way to work around this? I cant live with unrendered values when clicking a read only inline edit field.
I tried to use the def attribute with a function call for the existing render functions, but that does not work.
This question has an accepted answers - jump to answer
Answers
Hi,
The edit action will edit the raw value that is contained in the data. There is no option to render that into the field input box (in part because it would also then need to be de-rendered out of it). The key is to have the value that you want to edit in the data that is initially used to populate the table and then use the
columns.render
option in DataTables to modify it if you want to have a different value shown in the DataTable.Regards,
Allan
This is not an answer to my question. I am not interested in the column.render and it is also not possible to have the rendered values as data. I want the read only input to get rendered. That is not possible? Then read only is useless.
I need a solution for read only fields. When you don't define a field for editor then it throws an exception and afterwards the inline edit is broken. (uncaught exception: Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11)
I am not willing to make a selector which sets the onClick for inline Edit only on specific columns.
That is correct. Read only fields are exactly the same as any other field - they just have their
disabled
attribute set in the HTML. So the value they display is that value from the data.Only if you attempt to activate inline editing on a field that isn't editable. If a field isn't editable, then its best to simply not call the
inline()
method on cells for that field / column. This example shows a table where only some columns are inline editable.Could you clarify why not? A simple class selector or even an index check would be all that is needed.
Allan
Hi allan,
thank for the linked example, it does help. Writing my own selector would have gotten to complex since we are generating the columns of datatables from a factory and columnmappigs need to be translated then.