We are trying to bind select2 to the select box created in datatable action column when processing it shows select2 box but after load end it shows normal box with out select2 effect. We are creating one column in action as dropdown where we will be showing users in dropdown to select.
I tried with drawcollection as well still the issue reflect the same.
t.tblHelpers = {
actions: function () {
return function (d) {
return '<select name="approverName" value="' + d.id + '" id="location_' + d.id + '" class="a_location"></select>';
};
}
};
t.dTbl = t.locationApproverTable.DataTable({
autoWidth: false,
aoColumnDefs: [{
targets: 1,
bSortable: true,
render: t.tblHelpers.actions()
}],
order: [[0, 'asc']],
processing: true,
serverSide: true,
ajax: {
url: t.config.url.get_locations,
type: "get",
data: function(d) {
d._token = t.getToken();
}
},
columns: [
{data: 'a.text'},
{data: 'a.'}
],
fnInitComplete: function(oSettings, json) {
var api = this.api();
var searchBox = '<div class="input-group table-search-btns">'
+'<input type="text" class="form-control searchbox plain-search" placeholder="Press enter with search text" />'
+'<span class="input-group-addon btn-searchbox" data-toggle="tooltip" data-placement="left" data-original-title="Search"><i class="ps-icon plain-search-icon"></i></span>'
+'<span class="input-group-addon btn-reload-list" data-toggle="tooltip" data-placement="left" data-original-title="Refresh List"><i class="ps-icon fa fa-refresh"></i></span>'
+'</div>';
$(".a_location").select2({width:'100%'});;
},
drawCollection:function(){
console.log($(".a_location"));
$(".a_location").select2({width:'100%'});
}
});