Javascript

$(function () { WtmHomePage.initialise(); }); var WtmHomePage = { vars: { primaryTable: null, secondaryTable: null }, fn: { ajaxPost: function (sFunction, onSuccess, onError, data, passThroughData, iTimeoutMillis) { if (typeof iTimeoutMillis !== "number") { iTimeoutMillis = 30000; } if (typeof passThroughData === "undefined") { passThroughData = {}; } if (typeof onSuccess !== "function") { onSuccess = function () { }; } if (typeof onError !== "function") { onError = function () { }; } if (typeof data === "undefined") { data = null; } var sCsrfToken = $("input[name='__RequestVerificationToken']").val(); if (typeof sCsrfToken !== "string") { sCsrfToken = ""; } // Make ajax call $.ajax({ type: "POST", url: "../Home/" + sFunction, contentType: "application/json; charset=utf-8", processData: false, dataType: "json", headers: { "X-XSRF-Token": sCsrfToken }, data: data === null ? null : JSON.stringify(data), success: function (response, status, jqXhr) { // Only send the data back because we dont want to handle two separate // data layouts. This fails horribly if someone names a variable "d". if (typeof response.d !== "undefined") { onSuccess(response.d, status, jqXhr, passThroughData); } else { onSuccess(response, status, jqXhr, passThroughData); } }, error: function (jqXhr, status, errorName) { // Handle generic errors if they exist, otherwise forward to error handler if (jqXhr.status === 401) { // Unauthorised. Force a refresh window.location.href = window.location.href; return; } else if (status === "timeout") { // Function call timeout } onError(jqXhr, status, errorName, passThroughData); }, timeout: iTimeoutMillis }); }, }, initialise: function (data) { WtmHomePage.fn.ajaxPost("GetTaskLogList", function (data, status, jgXhr, params) { if (WtmHomePage.vars.primaryTable !== null) { WtmHomePage.vars.primaryTable.destroy(); } WtmHomePage.vars.primaryTable = $('#WTM_TABLE').dataTable({ "autoWidth": false, //selects first row automatically "order": [[2, "desc"]], initComplete: function () { this.api().row({ order: 'current' }, 0).select(); }, //IF PAGE <=1 HIDE PAGINATION "fnDrawCallback": function (oSettings) { if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) { $(oSettings.nTableWrapper).find('.dataTables_paginate').hide(); } }, "language": { "paginate": { previous: "<", next: ">", } }, "ordering": false, "processing": true, "searching": false, "info": false, "lengthChange": false, "autoWidth": false, "select": { style: "single", }, "data": JSON.parse(data), "columns": [ { "data": "TaskName", }, { "data": "StartDate", render: function (data, type, row) { var dateSplit = data.split(""); return type === "display" ? dateSplit[8] + dateSplit[9] + '/' + dateSplit[5] + dateSplit[6] + '/' + dateSplit[0] + dateSplit[1] + dateSplit[2] + dateSplit[3] + " " + dateSplit[11] + dateSplit[12] + ":" + dateSplit[14] + dateSplit[15] + ":" + dateSplit[17] + dateSplit[18] : data; } }, { "data": "EndDate", "render": function (data, type, row) { var dateSplit = data.split(""); return type === "display" ? dateSplit[8] + dateSplit[9] + '/' + dateSplit[5] + dateSplit[6] + '/' + dateSplit[0] + dateSplit[1] + dateSplit[2] + dateSplit[3] + " " + dateSplit[11] + dateSplit[12] + ":" + dateSplit[14] + dateSplit[15] + ":" + dateSplit[17] + dateSplit[18] : data; } }, { "data": "ErrorCount", "render": function (data, type, row) { var a = moment(row.EndDate) if (a.year() >= 9000) { return '<i class="far fa-dot-circle" style="color:yellow"></i>'; } if (data === 0) { return '<i class="far fa-dot-circle" style="color:green"></i>'; } return '<i class="far fa-dot-circle" style="color:red"></i>'; }, }, ], }); $("#LOG_TABLE tbody tr").css('cursor', 'pointer'); var oTable = $("#WTM_TABLE").DataTable(); //ONCLICK TABLE 1: DISPLAY CHILD TABLE INFO oTable.on("click", "tr", function () { var rowData = oTable.row(this).data(); var qTable = $('#WTM_LOG').DataTable(); qTable.columns(1).search(rowData.TaskName).draw(); }); }, function (jqXhr, status, errorName, params) { alert("'Parent table' Error") }, null, null, 30000); WtmHomePage.fn.ajaxPost("GetTaskLog", function (data, status, jgXhr, params) { if (WtmHomePage.vars.secondaryTable !== null) { WtmHomePage.vars.secondaryTable.destroy(); } //INIT CHILD TABLE WtmHomePage.vars.secondaryTable = $('#WTM_LOG').dataTable({ "deferRender": true, //HIDE PAGINATION IF PAGES <= 1 "fnDrawCallback": function (oSettings) { if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) { $(oSettings.nTableWrapper).find('.dataTables_paginate').hide(); } else { $(oSettings.nTableWrapper).find('.dataTables_paginate').show(); } }, "autoWidth": false, "dom": "rtp", "order": [[0, "desc"]], "pageLength": 20, "processing": true, "data": JSON.parse(data), "selector": ":not(:first-child)", "sPaginationType": "simple_numbers", "language": { "paginate": { previous: "<", next: ">", } }, "columns": [ { "data": "TaskSchedulerLogUid", "visible": false }, { "data": "TaskName", "visible": false, }, { "data": "StartDate", "render": function (data, type, row) { var dateSplit = data.split(""); if (type === "display") { return dateSplit[8] + dateSplit[9] + '/' + dateSplit[5] + dateSplit[6] + '/' + dateSplit[0] + dateSplit[1] + dateSplit[2] + dateSplit[3] + " " + dateSplit[11] + dateSplit[12] + ":" + dateSplit[14] + dateSplit[15] + ":" + dateSplit[17] + dateSplit[18]; } return data; }, }, { "data": "EndDate", "render": function (data, type, row) { var dateSplit = data.split(""); if (type === "display") { return dateSplit[8] + dateSplit[9] + '/' + dateSplit[5] + dateSplit[6] + '/' + dateSplit[0] + dateSplit[1] + dateSplit[2] + dateSplit[3] + " " + dateSplit[11] + dateSplit[12] + ":" + dateSplit[14] + dateSplit[15] + ":" + dateSplit[17] + dateSplit[18]; } return data; }, }, { "data": "ErrorCount", "render": function (data, type, row) { if (type === 'display') { return (data === 0) ? data = '<span data-search="0"></span>' : data = '<a href="http://localhost/WTM/LogError/Index?id=' + row.TaskSchedulerLogUid + '" type="hidden" class="fas fa-exclamation-triangle" style="color:red"></a>'; } return data; }, }, { "data": "EventCount", "render": function (data, type, row) { return (data > 0) ? data = '<a href="http://localhost/WTM/Details/Index?id=' + row.TaskSchedulerLogUid + '" type="hidden" class="fas fa-list" style="color:blue"></a>' : data = ''; }, }, ], columnDefs: [ { targets: 2 } ] }); var table = $('#WTM_TABLE').DataTable(); var nTable = $('#WTM_LOG').DataTable(); //TABLE RELOAD BUTTON $("#refresh").click(function () { table.ajax.reload(); nTable.ajax.reload(); }) // A load of other irrelevant functions... }, function (jqXhr, status, errorName, params) { alert("Child Table Error") }, null, null, 30000); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.