$.ajax load select option via dependent()
$.ajax load select option via dependent()
I'm trying to load the select option for field_02 via dependent() and $.ajax. The select option in the form is empty though. That's my setup:
editor = new $.fn.dataTable.Editor( {
ajax: "source.php",
table: "#mytable",
fields: [ {
label: "Field 01",
name: "field_01"
},{
label: "Field 02",
name: "field_02",
type: "select"
},
...
]
} );
editor.dependent( 'value', function ( val, data, callback ) {
$.ajax( {
url: 'source.php',
dataType: 'json',
success: function(data) {
$.each(data.data, function (i, item) {
test = item.value;
console.log(test)
//callback( test )
});
},
} );
} );
// console.log(test) returns me the values:
Value 01
Value 02
Value 03
How do I get the values in the Select form?
source.php looks like this
{"data":[{"DT_RowId":"row_1","account_id":"1","user_id":"1","value":"Value 01"},{"DT_RowId":"row_2","account_id":"1","user_id":"1","value":"Value 02"},{"DT_RowId":"row_3","account_id":"1","user_id":"1","value":"Value 03"}],"options":[],"files":[]}
This question has an accepted answers - jump to answer
Answers
And is it also possible to send a variable to the source similar to the dataTable instance?
Or some filtering when building the select form?
Yes, you can specify Ajax options when you call
dependent()
.Regarding the first issue, can you give me a link to the page so I can debug it please?
Thanks,
Allan
Hi Allan, I got it working. I'm not loading the select values via dependent() now, I switched to the JOIN method like for sites.name from your example here: https://editor.datatables.net/examples/simple/join.html
Many thanks!
That's great to hear - thanks for posting back!
Allan