How to use object on Editor?
How to use object on Editor?
yu yen kan
Posts: 65Questions: 31Answers: 0
function obj(array){
this.array = array;
this.array_id_list = function(){
var data = [];
for (var i = 0; i < this.array.length; i++) {
data.push(array[i]['id']);
}
return data;
}
}
var editor = new $.fn.dataTable.Editor( {
table: "#table",
ajax: {
create: "{{ Route("route1") }}",
edit: {
url: "{{ Route("route2") }}",
type: "PUT"
},
remove: {
url: "{{ Route("route3") }}",
type: "DELETE"
}
},
idSrc: 'id',
fields: [ {
label: "array:",
name: "array_id_list",
multiple: true,
type: "select",
options: [{ label : "abc", value: "1"}, { label: "bcd", value: "2"} ]
}
]
});
var data = new Array();
for(var i = 0; i < 5;i ++){
data[i] = new obj(i);
}
var table= $('#table).DataTable({
dom: "Bfrtip",
data: data,
select: true,
columns: [
{ data: 'array[, ].id, title: "Array id" }
],
buttons: [
{ extend: "create", editor: editor},
{ extend: "edit", editor: editor},
{ extend: "remove", editor: editor}
]
});
when I create a record, I get requested unknown parameter 'array_id_list' for new row, is there a setting to let me assign server returned data to the object?
This discussion has been closed.
Answers
You are using
'array[, ].id
(note your have a syntax error as there is a missing'
), butthis.array
in yourobj
is an integer.data: 'array'
for the column should show just the number.The naming of
this.array
is probably adding to the confusion since it isn't an array.Allan
no, this.array is an object of data that include id, name, and others data to display in table, array[, ].id will show all id in the array with delimiter ', '. The question I want to ask is how can I set default value when edit for multiple select type field
Not according to the above code it isn't:
where
i
is 1-5.Then:
So
this.array
is assigned the value of the argument which is passed in, which is 1-5. So unless I'm missing something,this.array
is a number in the above code.The structure of the default value should match whatever it is that you get when you run
field().val()
to get the value of the field.Allan