DataTables Editor 'select' Field Type
DataTables Editor 'select' Field Type
Let's say I have a field that I want to be a dropdown for selecting the name of a city.
I have a DataTables Editor field that is a 'select' type and is populated, for example, with these options:
{ label: 'London', value: '1' }
{ label: 'Paris', value: '2' }
{ label: 'New York', value: '3' }
Data is retrieved from the server and displayed in the table. There are 3 records for example:
{ cityName: 'London', cityId: '1' }
{ cityName: 'Paris', cityId: '2' }
{ cityName: 'New York', cityId: '3' }
When the data is retrieved and displayed in the table how do I tell DataTables Editor to default the 'select' field to be the 'cityId' value from the database? I.E. How to I set the 'selected' attribute for the option value that matches the 'cityId'?
Currently with the above scenario in both inline and main editing modes, the dropdown always defaults to the first value.
Answers
Ok, got it working using the 'editField' property for the DataTables column configuration. I was using inline editing mode and tracked down the resolution via this note: http://www.datatables.net/manual/tech-notes/11.