Steps:
Data-table with editor has multiple select2 in form.
->select2 is binded data with ajax.
->when datatables->create is called new form with select2 works fine , shows autocomplete retrieved through ajax and sets value to the text input when option selected from auto fill.
Question:
But not able to set the initial value to select2 when a particular row is selected from data-table.Noticed ajax calls in console for the select2 when edit button is clicked after row is selected.
screenshot :
code :
{
"label": "Area",
"name": "Area.AreaId",
"type": "select2",
"data": "Area.AreaName",
"initialValue":true,
"opts": {
"templateResult": function(data) {
return data.text;
},
"templateSelection": function(data) {
alert(JSON.stringify(data.text));
return data.text;
},
"minimumInputLength": 3,
"placeholder": 'Area',
"allowClear": true,
//"initialValue":true,
ajax: {
url: 'Area/json',
delay: 250 ,
dataType: 'json',
initialValue:true,
data: function (params) {
var query = {
value: params.term
}
// Query parameters will be ?search=[term]&type=public
return query;
},
processResults: function (data) {
return {
results: $.map(data, function(obj) {
return { id: obj.AreaId, text: obj.AreaName };
})
};
}
}
}
}
thanks