Advertisement
Guest User

jqgrid_config

a guest
Mar 31st, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //----------------------------------------------------------------------------------------------------------------------------------------
  2. // GRID CONFIGURATION
  3. //----------------------------------------------------------------------------------------------------------------------------------------
  4.     $grid.jqGrid({
  5.         /* See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options */
  6.         caption:         "rotations",
  7.         url:             "api/masters",
  8.         mtype:           "GET",
  9.         datatype:        "json",
  10.         height:          "100%", // 'auto',
  11.         colModel:        cm,
  12.         hidegrid:        false,
  13.         loadtext:        "Fetching Master Rotations ...",
  14.         loadonce:        true,              /* Load all data from server in a single request. */
  15.         ajaxGridOptions: { cache: true },   /* For local search. */
  16.         /* Note: not disabling 'nd' to enforce cache-refresh on stupid IE browser. */
  17.         prmNames:        { rows: null, page: null, search: null, sort: null, order: null },
  18.         lodui:           "block",
  19.         width:           $grid.closest(".mainContainer").width().toString() - "20",   /* FIXME: use relative sizes! */
  20.         shrinkToFit:     false,
  21.         rowList:         [10, 20, 30, 50, 100],
  22.         rowNum:          isColState ? myColumnsState.rowNum    : 20,
  23.         /* The following use the default setting from issue #3483. */
  24.         sortname:        isColState ? myColumnsState.sortname  : 'updated',
  25.         sortorder:       isColState ? myColumnsState.sortorder : 'desc',
  26.         search:          isColState ? myColumnsState.search    : false,
  27.         postData:        isColState ? { filters: myColumnsState.filters } : {},
  28.         pager:           '#summaryNavGrid',
  29.         viewrecords:     true,
  30.         gridview:        true,
  31.         ignoreCase:      true,
  32.         subGrid:         true,
  33.         /*
  34.          * Handlers:
  35.          */
  36.         jsonReader:      {
  37.             /* See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function */
  38.             repeatitems: true,
  39.             page:        function(obj)  { return 1; },
  40.             total:       function(obj)  { return 1; },
  41.             records:     function (obj) { return obj.length; },
  42.             subgrid: {
  43.                 root: "rows",
  44.                 repeatitems: true,
  45.                 cell: "cell"
  46.             }
  47.         },
  48.         beforeRequest: function() {
  49.             /* Configure search toolbar. */
  50.             $grid.jqGrid('filterToolbar', { stringResult: true, autosearch: true, searchOnEnter: false });
  51.         },
  52.         loadError: function (xhr, status, error) {
  53.             //  window.location.reload();
  54.             console.log(" status ", status, " errorr ", error);
  55.  
  56.         },
  57.         loadComplete: function (data) {
  58.             var $this = $(this), i;
  59.  
  60.             /* The following is true only on first load, since we use loadonce: true. */
  61.             if ($this.getGridParam('datatype') === "json" && isColState) {
  62.                 $this.jqGrid("remapColumns", myColumnsState.permutation, true);
  63.  
  64.                 /* Work-around: when changing rowNum, the row-number selection is not updated by default. */
  65.                 $(".ui-pg-selbox").val(myColumnsState.rowNum);
  66.             }
  67.  
  68.             refreshSearchingToolbar($this, myDefaultSearch);
  69.  
  70.             /* Sorting needs to come after refreshing the toolbar. */
  71.             if ($this.getGridParam('datatype') === "json" && isColState) {
  72.                 var params = {};
  73.  
  74.                 if (typeof(myColumnsState.sortname) !== "undefined")
  75.                     params.sortname = myColumnsState.sortname;
  76.                 if (typeof(myColumnsState.sortorder) !== "undefined")
  77.                     params.sortorder = myColumnsState.sortorder;
  78.                 if (typeof(myColumnsState.page) !== "undefined" && myColumnsState.page !== 1)
  79.                     params.page = myColumnsState.page;
  80.  
  81.                 i = getColumnIndex($this, myColumnsState.sortname);
  82.                 if (i > -1)
  83.                     $this.jqGrid("setGridParam", { lastsort: i });
  84.             }
  85.  
  86.             if (filteredRows.length) {
  87.                 $("#filterhint").html("<p><span class=\"ui-icon ui-icon-info\"></span>" +
  88.                 "<strong>Note:</strong> Rotation filter is applied, "               +
  89.                 "showing only " + filteredRows.length + " rotation"                 +
  90.                 (filteredRows.length === 1 ? "" : "s") + ".</p>");
  91.             } else {
  92.                 for (i = 0; i < idsOfSelectedRows.length; i++) {
  93.                     $this.jqGrid('setSelection', idsOfSelectedRows[i], true);
  94.                 }
  95.             }
  96.             saveColumnState.call($this, this.p.remapColumns);
  97.  
  98.             /*
  99.              * Header tooltips - mostly used to display the formula used by the given metric.
  100.              */
  101.             function setTooltipsOnColumnHeader(grid, iColumn, text) {
  102.                 var thd = jQuery("thead:first", grid[0].grid.hDiv)[0];
  103.  
  104.                 jQuery("tr.ui-jqgrid-labels th:eq(" + iColumn + ")", thd).attr("title", text);
  105.             }
  106.  
  107.             setTooltipsOnColumnHeader($grid,  1, "Name of rotation");
  108.             setTooltipsOnColumnHeader($grid,  2, "Rotation owner");
  109.             setTooltipsOnColumnHeader($grid,  3, "Time of last update");
  110.             setTooltipsOnColumnHeader($grid,  4, "Collective Bargaining Agreement");
  111.  
  112.             setTooltipsOnColumnHeader($grid,  5, "Total number of assigned shifts");
  113.             setTooltipsOnColumnHeader($grid,  6, "Number of baseline overages");
  114.             setTooltipsOnColumnHeader($grid,  7, "Number of baseline underages");
  115.  
  116.             setTooltipsOnColumnHeader($grid,  8, "Number of CBA violations");
  117.             setTooltipsOnColumnHeader($grid,  9, "Number of Best Practice violations");
  118.  
  119.             /* net baseline variance rate, netBaselineVarianceMetric */
  120.             setTooltipsOnColumnHeader($grid, 10, "100 * ((# of shifts over baseline - # of shifts under baseline) / (# of required baseline shifts)");
  121.             /* % of total lines with CBA violations, lineVarianceMetric */
  122.             setTooltipsOnColumnHeader($grid, 11, "100 * (# of lines with CBA violations) / (# of lines in the rotation)");
  123.             /* total baseline violations per week, totalBaselineMetric */
  124.             setTooltipsOnColumnHeader($grid, 12, "(# of shifts over baseline + # of shifts under baseline) / (# of weeks)");
  125.             /* hour variance per week, hourVarianceMetric */
  126.             setTooltipsOnColumnHeader($grid, 13, "(# of actual shifts - # of required shifts) * (worked hours) / (# of weeks)");
  127.             /* potential risk %, potRisk */
  128.             setTooltipsOnColumnHeader($grid, 14, "100 * ((# of shifts under baseline) * 2 + (# of shifts over baseline)) / (# of shifts)");
  129.             /* annual actual labour cost, labourCosts */
  130.             setTooltipsOnColumnHeader($grid, 15, "(sum of ($/hr * # of shifts * paid hours)) / (sum of weeks) * 52");
  131.             /* annual actual benefit cost, benefitCosts */
  132.             setTooltipsOnColumnHeader($grid, 16, "(sum of ($/hr * Benefits % * # of shifts * paid hours)) / (sum of weeks) * 52");
  133.             /* annual shift differential cost, shiftDifferential */
  134.             setTooltipsOnColumnHeader($grid, 17, "(sum of shift differential) / (sum of weeks) * 52");
  135.             /* annual weekend premium cost, weekendPremium */
  136.             setTooltipsOnColumnHeader($grid, 18, "(sum of weekend premium) / (sum of weeks) * 52");
  137.             /* annual actual total cost, actualTotalCosts */
  138.             setTooltipsOnColumnHeader($grid, 19, "(annual actual labour cost) + (annual actual benefit cost) + (annual actual shift differential cost) + (annual actual weekend premium cost)");
  139.             /* annual potential risk cost, riskCosts */
  140.             setTooltipsOnColumnHeader($grid, 20, "(annual actual total cost) * (potential risk %)");
  141.             /* annual total cost, totalCosts */
  142.             setTooltipsOnColumnHeader($grid, 21, "(annual actual total cost) + (annual potential risk cost)");
  143.             /* actual vs scheduled fte variance, fteVariance */
  144.             setTooltipsOnColumnHeader($grid, 22, "(scheduled fte) - (actual fte)");
  145.             /* annual fte cost variance, fteCostVariance */
  146.             setTooltipsOnColumnHeader($grid, 23, "((actual vs scheduled fte variance) * $/hr) / (sum of weeks) * 52 ");
  147.         },
  148.         ondblClickRow: function (id, iRow, iCol, e) {
  149.             $grid.jqGrid('toggleSubGridRow', id);
  150.  
  151.         },
  152.         onSelectRow: function (id, isSelected) {
  153.             $grid.jqGrid('toggleSubGridRow', id);
  154.         },
  155.         gridComplete: function () {                // fires after all the data is loaded into the grid and all other processes are complete.
  156.             $grid.tooltip({
  157.                 tooltipClass: "ui-state-highlight",
  158.                 open: function() {
  159.                     $(".ui-tooltip").stop(false, true).hide().slideDown("fast");
  160.                 },
  161.                 close: function() {
  162.                     $(".ui-tooltip").stop(false, true).hide();
  163.                 }
  164.             });
  165.         },
  166.         resizeStop: function () {
  167.             saveColumnState.call($grid, $grid[0].p.remapColumns);
  168.         },
  169.         subGridRowExpanded: function(subgrid_id, row_id) {
  170.  
  171.             var subgrid_table_id;
  172.             subgrid_table_id = subgrid_id+"_t";
  173.             jQuery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
  174.  
  175.             $("#" + subgrid_table_id).jqGrid({
  176.                 url:             "api/workplans?row=" + row_id,
  177.                 mtype:           "GET",
  178.                 datatype:        "json",
  179.                 loadtext:        "Fetching rotation metrics ...",
  180.                 loadonce:        true,              /* Load all data from server in a single request. */
  181.                 ajaxGridOptions: { cache: true },   /* For local search. */
  182.                 /* Note: not disabling 'nd' to enforce cache-refresh on stupid IE browser. */
  183.                 height:          "100%", // 'auto',
  184.                 width:           '100%',   /* FIXME: use relative sizes! */
  185.                 loadtext:        "Fetching Master Rotations ...",
  186.                 loadonce:        true,              /* Load all data from server in a single request. */
  187.                 ajaxGridOptions: { cache: true },   /* For local search. */
  188.                 /* Note: not disabling 'nd' to enforce cache-refresh on stupid IE browser. */
  189.                 prmNames:        { rows: null, page: null, search: null, sort: null, order: null },
  190.                 lodui:           "block",
  191.                 shrinkToFit:     false,
  192.                 sortname:        isColState ? myColumnsState.sortname  : 'updated',
  193.                 sortorder:       isColState ? myColumnsState.sortorder : 'desc',
  194.                 search:          isColState ? myColumnsState.search    : false,
  195.                 postData:        isColState ? { filters: myColumnsState.filters } : {},
  196.                 viewrecords:     true,
  197.                 gridview:        true,
  198.                 ignoreCase:      true,
  199.                 shrinkToFit:     false,
  200.                 multiselect:     true,
  201.                 colModel:    [
  202.                     { label: "Workplan Name", name: "value.name", align: "left", classes: "linkable", hidden: false, width: 180,
  203.                         cellattr: function (rowId, val, rawObject, cm, rdata) {
  204.                             return ' title = "' + val + " - " + (rawObject.value ? rawObject.value.status : rawObject.status) + '"';
  205.                         }
  206.                     },
  207.                     { label: "CBA",     name:  "value.agreement", align:     "center", classes:   "linkable", hidden:    false, width:     85 },
  208.                     { label: "owner",   name: "value.creator",   align: "left",       classes: "linkable",   hidden: false,     width: 120    },
  209.  
  210.                     { label: "updated", name: "updated",         align: "center",     classes: "linkable",   hidden: false,     width: 95,
  211.                         jsonmap: "value.updated", sorttype: 'date', search: true, stype: 'text', formatter: "date", formatoptions: {
  212.                         /* See http://php.net/manual/en/function.date.php */
  213.                         srcformat: "Y-m-d\\TH:i:s",
  214.                         newformat: "Y-m-d"              /* has to match 'dateFormat' in datePicker() below. */
  215.                     },
  216.                         cellattr: function (rowId, val, rawObject, cm, rdata) {
  217.                             return ' title = "' + moment(rdata.updated).calendar() + '"';
  218.                         },
  219.                         searchoptions: {
  220.                             sopt: ['ge'],
  221.                             attr: {title: "Set the start date of the selection"},
  222.                             dataInit: function (elem) {
  223.                                 setTimeout(function () {
  224.                                     /* See http://api.jqueryui.com/datepicker/ */
  225.                                     $(elem).datepicker({
  226.                                         /* For dateFormat, see http://api.jqueryui.com/datepicker/#utility-formatDate */
  227.                                         dateFormat: 'yy-mm-dd', autoSize: true, maxDate: 0, /* Today's date */ showAnim: "slideDown", duration: "fast", firstDay: 1, /* Monday */changeYear: true,
  228.                                         changeMonth: true, showButtonPanel: true, currentText: "Today", /* Disable 'Today' button (does not work well). */
  229.                                         onSelect: function () {
  230.                                             if (this.id.substr(0, 3) === "gs_") {
  231.                                                 setTimeout(function () {
  232.                                                     $grid[0].triggerToolbar();
  233.                                                 }, 50);
  234.                                             } else {
  235.                                                 /* To refresh the filter. */
  236.                                                 $(this).trigger('change');
  237.                                             }
  238.                                         }
  239.                                     });
  240.                                 }, 100);
  241.                             }
  242.                         }
  243.                     },
  244.                     { label: "total # of shifts",           name: "value.numShifts",        align: "center", classes: "linkable", hidden: true, sorttype: "float", width: 76, searchoptions: {sopt: ['ge']} },
  245.                     { label: "# of shifts over baseline",   name: "value.baselineOver",     align: "center", classes: "linkable", hidden: true, sorttype: "float", width: 76, searchoptions: {sopt: ['ge']} },
  246.                     { label: "# of shifts under baseline",  name: "value.baselineUnder",    align: "center", classes: "linkable", hidden: true, sorttype: "float", width: 76, searchoptions: {sopt: ['ge']} },
  247.                     { label: "cba violations",              name: "value.constraintMetric", align: "center", classes: "linkable", hidden: false,sorttype: "integer",width: 76,searchoptions: {sopt: ['ge']},
  248.                         cellattr: function (rowId, val, rawObject, cm, rdata) {
  249.                             return ' title = "' + (rawObject.value ? rawObject.value.cbaViolations : rawObject.cbaViolations) + '"';
  250.                         }
  251.                     },
  252.                     { label: "bp violations",               name: "value.bestPracticeMetric",align: "center", classes: "linkable", hidden: false,sorttype: "integer",width: 76, searchoptions: {sopt: ['ge']},
  253.                         cellattr: function (rowId, val, rawObject, cm, rdata) {
  254.                             return ' title = "' + (rawObject.value ? rawObject.value.bpViolations : rawObject.bpViolations) + '"';
  255.                         }
  256.                     },
  257.                     { label: "net baseline variance rate", name: "value.netBaselineVarianceMetric", align: "center", classes: "linkable", hidden: false, sorttype: "float", width: 76, searchoptions: {sopt: ['ge']},
  258.                         formatter: function (cellvalue, options, rowObject) {
  259.                             if (cellvalue !== null)
  260.                                 return fmtPercent(cellvalue);
  261.                             return "<span style='background-color: #F78D8D'>no baseline</span>";
  262.                         }
  263.                     }
  264.                 ],
  265.                 sortname: 'EmpId',
  266.                 viewrecords: true,
  267.                 sortorder: "asc",
  268.                 onSelectRow: function (id, isSelected, e) {
  269.                     var master = this.id.split('_')[1];
  270.                     updateIdsOfSelectedRows(id, isSelected, master,  scope);
  271.                     saveColumnState.call($grid, $grid[0].p.remapColumns);
  272.                     return false;
  273.                 },
  274.                 onSelectAll: function (aRowids, isSelected) {
  275.                     var i, count, id,
  276.                         master = this.id.split('_')[1];
  277.                     for (i = 0, count = aRowids.length; i < count; i++) {
  278.                         id = aRowids[i];
  279.                         updateIdsOfSelectedRows(id, isSelected, master,  scope);
  280.                     }
  281.                     saveColumnState.call($grid, $grid[0].p.remapColumns);
  282.                 }
  283.             });
  284.         }
  285.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement