Using a custom editor field is it possible to pass data from another table column into the set method
I am attempting to do pass the value of another column as an additional option to a custom editor. Hopefully the markup below will clarify my issue.
{
label: "Status:",
name: "Status", // this a text description of the status as sent by the server
type: "MyCustomEditor", // my custom editor that will format the status with an icon and text (no input field)
?????????
customOption: {
// how do I pass in the status code value from another column into this custom editor
name:"StatusCode" // StatusCode comes from server (1,2,3,4) etc only use is to choose icons and colours for the status description
}
},
More complete sample
_fieldTypes.RowStatus = {
var statusValueFromTable; // 0,1,2,3,4 etc
?????????
customOption:function(conf, val)
{
statusValueFromTable = val;
}
create: function (conf) {
conf._input = $("<span></span>");
return conf._input;
},
set: function (conf, val) {
var iconInfoMap = [
{ colour: "grey", icon: "icon-pen" },
{ colour: "green", icon: "icon-check-mark" },
{ colour: "red", icon: "icon-cross" }
];
?????????
iconInfo = iconInfoMap[statusValueFromTable];
var html = '<span class="rowcolordatatable ' + iconInfo.colour + '"><i class="' + iconInfo.icon + '"></i><span> ' + val + '</span></span>';
conf._input.html(html);
},
};
editor = new $.fn.dataTable.Editor({
"idSrc": "Id",
"table": "#aTable",
"fields":
[
{
label: "Status:",
name: "Status",
type: "RowStatus",
?????????
customOption: {
// how do I pass in the status code value from another column into
// this custom editor
name:"StatusCode" // want to pass 1,2,3,4 etc
}
},
{
// i can see the status code on the form easily but this is not what i want
label: "StatusCode:",
name: "StatusCode",
type: "readonly",
},
{
label: "City:",
name: "Address3",
type: "readonly"
},
{
label: "Country:",
name: "Address4",
type: "readonly"
}
]
});
var table = $('#aTable').DataTable({
"columns": [
{ "data": "Firstname" },
{ "data": "Lastname" },
{
"data": "StatusCode", render: function (data, type, row) {
if (data == 1) {
return '<span class="gray"><i class="icon-pen"></i> <span>' + row.Status + '</span></span>';
}
if (data == 2) {
return '<span class="green"><i class="icon-check-mark"></i> <span>' + row.Status + '</span></span>';
}
if (data == 3) {
return '<span class="red"><i class="icon-cross"></i> <span>' + row.Status + '</span></span>';
}
// simplified ..
return data;
}
},
]
});
$('#aTable tbody').on('click', 'button', function () {
editor.edit($(this).closest('tr'), {
?????????
// do i need to pass the statuscode value into the editor here??
title: 'View Record',
});
});