Add Default to Select options
Add Default to Select options
Hi everyone, please forgive me if this is a repeated question, i did searched through the forum but could not get a clear answer. Having said that, this is my question: I have a select field whose option is being populated by records from one of my tables in the db. when creating a new row, it automatically selects the first option and i don not want this to happen because the select field is optional so i want the first option to be have a null id and "select one" label. Also if an existing row is being edited i will want the null id and "select one " label to also be among the drop down options. I read on the forum that this can be done with a placeholder option but i just can't seem to understand how to structure it . this is my editor code -:
``var editor6 = new $.fn.dataTable.Editor( {
ajax: 'assets/datatable_assets/php/table.nestor_accountstructures.php',
table: '#nestor_accountstructures',
fields: [
{
"label": "Structure Name:",
"name": "nestor_accountstructures.accountstructure_name"
},
{
"label": "Segment 1:",
"name": "nestor_accountstructures.accountstructure_segment1",
"type": "select"
}
....```
Please how do i add the placeholder to the above, thanks. @rf1234
This question has accepted answers - jump to:
Answers
https://editor.datatables.net/reference/field/select
for select fields you can use "placeholder" directly, for other fields you would need to set an "attr" object as above
Its working thanks @rf1234 . But the default option ['bla bla bla'] does not appear selection when editing a row
No, because it is a placeholder, not a default option. If you want the placeholder to be a default select option as well you would need to add it to the options that you use and put it on top of that list.
Alright, thank you very much
Editor's
select
field does actually have an option to be able to use the placeholder as a value -placeholderDisabled
andplaceholderValue
are the two properties of interest there:select
.Allan
Thanks @allan ! Good to know.
Thanks gentlemen