//Cylinders function InitCylinders(data) { editorCyl = new $.fn.dataTable.Editor({ data: data, table: "#tblCylinders", idSrc: "RID", fields: [ { "name": "OPDFullQty", "attr": { "type": "number" } }, { "name": "OPDEmptyQty", "attr": { "type": "number" } }, { "name": "NonOPDFullQty", "attr": { "type": "number" } }, { "name": "NonOPDEmptyQty", "attr": { "type": "number" } }, { "name": "WIPQTY", "attr": { "type": "number" } }, { "name": "MinedDefective", "attr": { "type": "number" } }, { "name": "Defective", "attr": { "type": "number" } } ], formOptions: { inline: { onBlur: 'submit', submit: 'allIfChanged', onFieldError: 'focus' } } }); editorCyl.on("initCreate", editorCylInitCreate); editorCyl.on("initEdit", editorCylInitEdit); editorCyl.on("preSubmit", editorCylPreSubmit); editorCyl.on("submitComplete", editorCylSubmitComplete); // Activate an inline edit on click of a table cell $('#tblCylinders').on('click', 'tbody td.editable', function (e) { editorCyl.inline(this); }); tblCylinders = $("#tblCylinders").DataTable({ dom: "Bfrtip", data: data, paging: false, responsive: { details: { type: "column" } }, // orderFixed: [1, 'asc'], order: [[3, "asc"], [4, "asc"]], columns: [ { data: null, defaultContent: "" }, { data: null, defaultContent: "" }, { "data": "Location", "responsivePriority": 1 }, { "data": "AreaDescription", "responsivePriority": 3 }, { "data": "OPDFullQty", "responsivePriority": 4, "className": "editable" }, { "data": "OPDEmptyQty", "responsivePriority": 5, "className": "editable" }, { "data": "NonOPDFullQty", "responsivePriority": 6, "className": "editable" }, { "data": "NonOPDEmptyQty", "responsivePriority": 7, "className": "editable" }, { "data": "WIPQTY", "responsivePriority": 8, "className": "editable" }, { "data": "MinedDefective", "responsivePriority": 9, "className": "editable" }, { "data": "Defective", "responsivePriority": 10, "className": "editable" } ], keys: { columns: '.editable', editorKeys: 'tab-only', editor: editorCyl, editOnFocus: true, editAutoSelect: true }, select: { style: 'api' }, columnDefs: [ { className: "control", targets: [0] }, { orderable: false, targets: [0, 1] }, { visible: false, targets: [1] } ], rowGroup: { dataSrc: "inventoryType", startRender: function startRender(rows, group) { return group + " (" + rows.count() + ")"; } }, lengthChange: false, buttons: [ { extend: "create", editor: editorCyl }, { extend: "print", editor: editorCyl, exportOptions: { modifier: { order: "current" } } }, { extend: 'collection', text: 'Group By...', autoClose: true, buttons: [ { text: "Group By Process", action: function action(e, dt, node, config) { GroupBy("inventoryType"); } }, { text: "Group By Ship From", action: function action(e, dt, node, config) { GroupBy("shipFromDistribName"); } }, { text: "Group By Ship To", action: function action(e, dt, node, config) { GroupBy("shipToDistribName"); } }, { text: "Group By Ship Date", action: function action(e, dt, node, config) { GroupBy("shipDate"); } }, { text: "Group By Last Modified", action: function action(e, dt, node, config) { GroupBy("lastModified"); } }, { text: "Group By Deadline", action: function action(e, dt, node, config) { GroupBy("deadline"); } }, { text: "Group By Status", action: function action(e, dt, node, config) { GroupBy("status"); } } ] }, { text: "Remove Groups", enabled: false, action: function action(e, dt, node, config) { GroupBy(""); } } ] }); tblCylinders .rowGroup() .disable() .draw(); // Change the fixed ordering when the data source is updated tblCylinders.on("rowgroup-datasrc", function (e, dt, val) { var columns = [ { name: lastMod.toString(), index: 7, sort: "desc" }, { name: byDeadline.toString(), index: 9, sort: "desc" }, { name: byShipDate.toString(), index: 6, sort: "asc" }, { name: "inventoryType", index: 2, sort: "asc" }, { name: "status", index: 8, sort: "asc" }, { name: "shipFromDistribName", index: 4, sort: "asc" }, { name: "shipToDistribName", index: 5, sort: "asc" } ]; conlog.ajax(val); conlog.ajax(JSON.stringify(val)); var key = $.grep(columns, function (k) { return k.name == val.toString(); })[0]; var sort = [[key.index, key.sort]]; tblCylinders.order .fixed({ pre: sort //, //post: [2, 'asc'] }) .draw(); }); //tblCylinders.on('key-blur', function (e, datatable, cell) { // if (editorCyl.inError()) { // tblCylinders.cell(cell).focus(); // cell.focus(); // tblCylinders.draw(); // return false; // } //}); var grp = getCookie("cylGroupBy"); if (grp != "") { GroupBy(grp); } } //function GroupBy(column) { // var columns = [ // { name: "shipDate", header: "Ship Date" }, // { name: "lastModified", header: "Last Modified" }, // { name: "deadline", header: "Deadline" }, // { name: "inventoryType", header: "Process" }, // { name: "status", header: "Status" }, // { name: "shipFromDistribName", header: "Ship From" }, // { name: "shipToDistribName", header: "Ship To" } // ]; // if (column == "") { // tblCylinders.order.fixed({ // pre: [] //, // //post: [] // }); // tblCylinders // .rowGroup() // .disable() // .draw(); // tblCylinders.buttons(2).disable(); // tblCylinders.column(1).visible(false); // $(tblCylinders.column(1).header()).text(""); // setCookie("cylGroupBy", null, 30); // return true; // } // setCookie("cylGroupBy", column, 30); // tblCylinders.buttons(2).enable(); // tblCylinders.column(1).visible(true); // var columnInfo = $.grep(columns, function (k) { // return k.name == column; // })[0]; // $(tblCylinders.column(0).header()).text("Group By " + columnInfo.header); // $(tblCylinders.column(1).header()).text("Group By " + columnInfo.header); // if (column == "lastModified") { // tblCylinders // .rowGroup() // .enable() // .dataSrc(lastMod); // } else if (column == "deadline") { // tblCylinders // .rowGroup() // .enable() // .dataSrc(byDeadline); // } else if (column == "shipDate") { // tblCylinders // .rowGroup() // .enable() // .dataSrc(byShipDate); // } else { // tblCylinders // .rowGroup() // .enable() // .dataSrc(column); // } // tblCylinders.columns.adjust().draw(); //} function RequireMinVal(fld, parsed, minVal) { if (isNaN(parsed)) fld.error("Must be a valid whole number."); else if (parsed < minVal) fld.error("Must be at least " + minVal + "."); } function editorCylInitCreate(e) { } function editorCylInitEdit(e, node, data) { } function editorCylSubmitComplete(e, json, data, action) { } function editorCylPreSubmit(e, o, action) { conlog.ajax("presubmit"); var fld; var parsed; fld = this.field(this.displayed()[0]); fld.error(""); parsed = parseInt(fld.val()); RequireMinVal(fld, parsed, 0); if (this.inError()) { return false; }