Advertisement
GWibisono

jgrid

Apr 11th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <title>P-Dos # List Of Wells</title>
  2. <link rel="stylesheet" href="<?= base_url() ?>components/_mod/jquery-ui/jquery-ui.css" />
  3. <link rel="stylesheet" href="<?= base_url() ?>components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css" />
  4. <link rel="stylesheet" href="<?= base_url() ?>components/_mod/jqgrid/ui.jqgrid.css" />
  5.  
  6. <!-- ajax layout which only needs content area -->
  7. <div class="row">
  8.     <div class="col-xs-12">
  9.         <!-- PAGE CONTENT BEGINS -->
  10.         <table id="grid-table"></table>
  11.         <div id="grid-pager"></div>        
  12.         <!-- PAGE CONTENT ENDS -->
  13.     </div><!-- /.col -->
  14. </div><!-- /.row -->
  15.  
  16. <!-- page specific plugin scripts -->
  17. <script type="text/javascript">
  18. var JS_SITE_URL = "<?= site_url() ?>";
  19. var JS_BASE_URL = "<?= base_url() ?>";
  20.  
  21. var company_id = "<?= $company_id ?>";
  22. var region_id = "<?= $region_id ?>";
  23. var company_name = "<?= $com->company_name ?>";
  24. var region_name = "<?= $reg->region_name ?>";
  25.  
  26. var scripts = [null,
  27.     JS_BASE_URL + "components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js",
  28.     JS_BASE_URL + "components/jqGrid/js/jquery.jqGrid.js",
  29.     JS_BASE_URL + "components/jqGrid/js/i18n/grid.locale-en.js", null];
  30.  
  31. $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
  32.     //inline scripts related to this page
  33.     jQuery(function ($) {
  34.         var grid_selector = "#grid-table";
  35.         var pager_selector = "#grid-pager";
  36.  
  37.         //resize to fit page size
  38.         $(window).on('resize.jqGrid', function () {
  39.             $(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
  40.         })
  41.  
  42.         //resize on sidebar collapse/expand
  43.         var parent_column = $(grid_selector).closest('[class*="col-"]');
  44.         $(document).on('settings.ace.jqGrid', function (ev, event_name, collapsed) {
  45.             if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
  46.                 //setTimeout is for webkit only to give time for DOM changes and then redraw!!!
  47.                 setTimeout(function () {
  48.                     $(grid_selector).jqGrid('setGridWidth', parent_column.width());
  49.                 }, 0);
  50.             }
  51.         })
  52.  
  53.         var selr = jQuery(grid_selector).jqGrid('getGridParam', 'selrow');
  54.         jQuery(grid_selector).setGridParam({
  55.             datatype : 'json',
  56.             page : 1
  57.         }).trigger("reloadGrid");
  58.         jQuery(grid_selector).jqGrid({
  59.             datatype : "json",
  60.             url : JS_SITE_URL + "/well/getListWells",
  61.             height : "100%",
  62.             colNames : ['', 'Wells Id', 'Wells Name', 'Drilling Rig', 'Drilling Contractor', 'Spud Date', 'TD Date', 'TD Depth'],
  63.             colModel :[
  64.                 {name:'act',index:'act', width:100,sortable:false},
  65.                 {
  66.                     name : 'wells_id',
  67.                     index : 'wells_id',  
  68.                     width : 150
  69.                 },
  70.                 {name:'wells_name',index:'wells_name', width:300, editable:true},
  71.                  {
  72.                     name : 'drilling_rig',
  73.                     index : 'drilling_rig',
  74.                     editable : true,
  75.                     align : 'left',
  76.                     width : 300
  77.                 }, {
  78.                     name : 'drilling_contractor',
  79.                     index : 'drilling_contractor',
  80.                     editable : true,
  81.                     align : 'left',
  82.                     width : 300,
  83.                     editoptions : {}
  84.                 }, {
  85.                     name : 'spud_date',
  86.                     index : 'spud_date',
  87.                     editable : true,
  88.                     align : 'center',
  89.                     width : 150,
  90.                     editoptions : {},
  91.                     sorttype : "date",
  92.                     unformat : pickDate,
  93.                     formatter : 'date',
  94.                     formatoptions : {
  95.                         srcformat : 'ISO8601Long',
  96.                         newformat : 'd-m-Y H:i',
  97.                         defaultValue : null
  98.                     }
  99.                 }, {
  100.                     name : 'td_date',
  101.                     index : 'td_date',
  102.                     editable : true,
  103.                     align : 'center',
  104.                     width : 150,
  105.                     editoptions : {},
  106.                     sorttype : "date",
  107.                     unformat : pickDate,
  108.                     formatter : 'date',
  109.                     formatoptions : {
  110.                         srcformat : 'ISO8601Long',
  111.                         newformat : 'd-m-Y H:i',
  112.                         defaultValue : null
  113.                     }
  114.                 }, {
  115.                     name : 'td_depth',
  116.                     index : 'td_depth',
  117.                     editable : true,
  118.                     align : 'center',
  119.                     width : 150,
  120.                     editoptions : {},
  121.                 }
  122.             ],
  123.             gridComplete: function(){
  124.                 var ids = jQuery(grid_selector).jqGrid('getDataIDs');
  125.                 for(var i=0;i < ids.length;i++){
  126.                     var cl = ids[i];
  127.                     be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#rowed2').editRow('"+cl+"');\" />";
  128.                     se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#rowed2').saveRow('"+cl+"');\" />";
  129.                     ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#rowed2').restoreRow('"+cl+"');\" />";
  130.                     jQuery("#rowed2").jqGrid('setRowData',ids[i],{act:be+se+ce});
  131.                 }
  132.             },
  133.         });
  134. /*     
  135.         jQuery(grid_selector).jqGrid({
  136.             datatype : "json",
  137.             url : JS_SITE_URL + "/well/getListWells",
  138.             mtype : "POST",
  139.             height : "100%",
  140.             colNames : ['', 'Wells Id', 'Wells Name', 'Drilling Rig', 'Drilling Contractor', 'Spud Date', 'TD Date', 'TD Depth'],
  141.             colModel : [{
  142.                     name : '',
  143.                     index : '',
  144.                     width : 100,
  145.                     fixed : true,
  146.                     sortable : false,
  147.                     resize : false,
  148.                     formatter : 'actions',
  149.                     formatoptions : {
  150.                         keys : true,
  151.                         deldata : {
  152.                             id : $(selr + 'wells_id').val()
  153.                         },
  154.                         delOptions : {
  155.                             recreateForm : true,
  156.                             beforeShowForm : beforeDeleteCallback,
  157.                         },
  158.                         adwbutton : false
  159.                     },
  160.                     search : false
  161.                 }, {
  162.                     name : 'wells_id',
  163.                     index : 'wells_id',
  164.                     editable : false,
  165.                     align : 'center',
  166.                     width : 150,
  167.                     searchoptions : {
  168.                         clearSearch : false
  169.                     }
  170.                 }, {
  171.                     name : 'wells_name',
  172.                     index : 'wells_name',
  173.                     editable : true,
  174.                     align : 'left',
  175.                     width : 300,
  176.                     searchoptions : {
  177.                         clearSearch : false
  178.                     }
  179.                 }, {
  180.                     name : 'drilling_rig',
  181.                     index : 'drilling_rig',
  182.                     editable : true,
  183.                     align : 'left',
  184.                     width : 300,
  185.                     searchoptions : {
  186.                         clearSearch : false
  187.                     }
  188.                 }, {
  189.                     name : 'drilling_contractor',
  190.                     index : 'drilling_contractor',
  191.                     editable : true,
  192.                     align : 'left',
  193.                     width : 300,
  194.                     editoptions : {},
  195.                     searchoptions : {
  196.                         clearSearch : false
  197.                     }
  198.                 }, {
  199.                     name : 'spud_date',
  200.                     index : 'spud_date',
  201.                     editable : true,
  202.                     align : 'center',
  203.                     width : 150,
  204.                     editoptions : {},
  205.                     searchoptions : {
  206.                         clearSearch : false
  207.                     },
  208.                     sorttype : "date",
  209.                     unformat : pickDate,
  210.                     formatter : 'date',
  211.                     formatoptions : {
  212.                         srcformat : 'ISO8601Long',
  213.                         newformat : 'd-m-Y H:i',
  214.                         defaultValue : null
  215.                     }
  216.                 }, {
  217.                     name : 'td_date',
  218.                     index : 'td_date',
  219.                     editable : true,
  220.                     align : 'center',
  221.                     width : 150,
  222.                     editoptions : {},
  223.                     searchoptions : {
  224.                         clearSearch : false
  225.                     },
  226.                     sorttype : "date",
  227.                     unformat : pickDate,
  228.                     formatter : 'date',
  229.                     formatoptions : {
  230.                         srcformat : 'ISO8601Long',
  231.                         newformat : 'd-m-Y H:i',
  232.                         defaultValue : null
  233.                     }
  234.                 }, {
  235.                     name : 'td_depth',
  236.                     index : 'td_depth',
  237.                     editable : true,
  238.                     align : 'center',
  239.                     width : 150,
  240.                     editoptions : {},
  241.                     searchoptions : {
  242.                         clearSearch : false
  243.                     }
  244.                 }
  245.             ],
  246.             jsonReader : {
  247.                 root : "rows",
  248.                 page : "page",
  249.                 total : "total",
  250.                 records : "records",
  251.                 repeatitems : true,
  252.                 cell : "cell",
  253.                 id : "id",
  254.                 userdata : "userdata"
  255.             },
  256.             viewrecords : true,
  257.             rowNum : 10,
  258.             rowList : [10, 20, 30, 50, 100],
  259.             pager : pager_selector,
  260.             loadonce : false,
  261.             altRows : true,
  262.             closeAfterAdd : true,
  263.             closeAfterEdit : true,
  264.             multiselect : true,
  265.             multiboxonly : true,
  266.             shrinkToFit : false,
  267.             loadComplete : function () {
  268.                 var table = this;
  269.                 setTimeout(function () {
  270.                     styleCheckbox(table);
  271.                     updateActionIcons(table);
  272.                     updatePagerIcons(table);
  273.                     enableTooltips(table);
  274.                 }, 0);
  275.             },
  276.             editurl : JS_SITE_URL + "/well/simpan_wells?cid=" + company_id + "&rid=" + region_id,
  277.             reloadAfterSubmit : true,
  278.             caption : "List of Well " + company_name + "#Region : " + region_name,
  279.             ondblClickRow : function (rowId) {
  280.                 location.href = "#docs/file_wells?wid=" + rowId;
  281.             },
  282.             serializeGridData : function (postData) {
  283.                 var newPostData = $.extend(postData, {
  284.                         companyID : company_id,
  285.                         regionID : region_id
  286.                     });
  287.                 return $.param(newPostData);
  288.             }
  289.         });
  290. */
  291.         jQuery(grid_selector).jqGrid('filterToolbar', {
  292.             autosearch : true,
  293.             stringResult : true,
  294.             searchOperators : false,
  295.             searchOnEnter : false,
  296.             defaultSearch : "cn",
  297.             enableClear : false
  298.         });
  299.  
  300.         $(window).triggerHandler('resize.jqGrid'); //trigger window resize to make the grid get the correct size
  301.         //enable datepicker
  302.         function pickDate(cellvalue, options, cell) {
  303.             setTimeout(function () {
  304.                 $(cell).find('input[type=text]')
  305.                 .datepicker({
  306.                     format : 'dd-mm-yyyy',
  307.                     autoclose : true
  308.                 });
  309.             }, 0);
  310.         }
  311.  
  312.         jQuery(grid_selector).jqGrid('navGrid', pager_selector, { //navbar options
  313.             edit : false,
  314.             editicon : 'ace-icon fa fa-pencil blue',
  315.             add : true,
  316.             addicon : 'ace-icon fa fa-plus-circle purple',
  317.             del : false,
  318.             delicon : 'ace-icon fa fa-trash-o red',
  319.             search : false,
  320.             searchicon : 'ace-icon fa fa-search orange',
  321.             refresh : true,
  322.             refreshicon : 'ace-icon fa fa-refresh green',
  323.             view : false,
  324.             viewicon : 'ace-icon fa fa-search-plus grey',
  325.         }, {
  326.             width : 500,
  327.             editCaption : 'Edit Wells',
  328.             bSubmit : "Simpan",
  329.             bCancel : "Batal",
  330.             closeAfterEdit : true,
  331.             closeOnEscape : true,
  332.             reloadAfterSubmit : true,
  333.             refreshtext : 'Reload',
  334.             recreateForm : true,
  335.             beforeShowForm : function (e) {
  336.                 var form = $(e[0]);
  337.                 form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  338.                 style_edit_form(form);
  339.             }
  340.         }, {
  341.             //new record form
  342.             width : 500,
  343.             addCaption : 'Add Wells',
  344.             closeAfterAdd : true,
  345.             recreateForm : true,
  346.             viewPagerButtons : false,
  347.             beforeShowForm : function (e) {
  348.                 var form = $(e[0]);
  349.                 form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
  350.                 .wrapInner('<div class="widget-header" />')
  351.                 style_edit_form(form);
  352.             }
  353.         }, {
  354.             //delete record form
  355.             width : 300,
  356.             caption : "Delete Wells",
  357.             msg : "Are You Sure?",
  358.             bSubmit : "Hapus",
  359.             bCancel : "Batal",
  360.             recreateForm : true,
  361.             beforeShowForm : function (e) {
  362.                 var form = $(e[0]);
  363.                 if (form.data('styled'))
  364.                     return false;
  365.                 form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  366.                 style_delete_form(form);
  367.             }
  368.         }, {
  369.             //search form
  370.             recreateForm : true,
  371.             afterShowSearch : function (e) {
  372.                 var form = $(e[0]);
  373.                 form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
  374.                 style_search_form(form);
  375.             },
  376.             afterRedraw : function () {
  377.                 style_search_filters($(this));
  378.             },
  379.             multipleSearch : true
  380.         }, {
  381.             //view record form
  382.             recreateForm : true,
  383.             beforeShowForm : function (e) {
  384.                 var form = $(e[0]);
  385.                 form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
  386.             }
  387.         })
  388.  
  389.         function style_edit_form(form) {
  390.             //update buttons classes
  391.             var buttons = form.next().find('.EditButton .fm-button');
  392.             buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide(); //ui-icon, s-icon
  393.             buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
  394.             buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')
  395.             buttons = form.next().find('.navButton a');
  396.             buttons.find('.ui-icon').hide();
  397.             buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
  398.             buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
  399.         }
  400.         function style_delete_form(form) {
  401.             var buttons = form.next().find('.EditButton .fm-button');
  402.             buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide(); //ui-icon, s-icon
  403.             buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
  404.             buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
  405.         }
  406.         function style_search_filters(form) {
  407.             form.find('.delete-rule').val('X');
  408.             form.find('.add-rule').addClass('btn btn-xs btn-primary');
  409.             form.find('.add-group').addClass('btn btn-xs btn-success');
  410.             form.find('.delete-group').addClass('btn btn-xs btn-danger');
  411.         }
  412.         function style_search_form(form) {
  413.             var dialog = form.closest('.ui-jqdialog');
  414.             var buttons = dialog.find('.EditTable')
  415.                 buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
  416.             buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
  417.             buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
  418.         }
  419.  
  420.         function beforeDeleteCallback(e) {
  421.             var form = $(e[0]);
  422.             if (form.data('styled'))
  423.                 return false;
  424.             form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  425.             style_delete_form(form);
  426.             //form.data('styled', true);
  427.         }
  428.  
  429.         function beforeEditCallback(e) {
  430.             var form = $(e[0]);
  431.             form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  432.             style_edit_form(form);
  433.         }
  434.  
  435.         //it causes some flicker when reloading or navigating grid
  436.         //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
  437.         //or go back to default browser checkbox styles for the grid
  438.         function styleCheckbox(table) {}
  439.  
  440.         function updateActionIcons(table) {}
  441.  
  442.         //replace icons with FontAwesome icons like above
  443.         function updatePagerIcons(table) {
  444.             var replacement = {
  445.                 'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
  446.                 'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
  447.                 'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
  448.                 'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
  449.             };
  450.             $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
  451.                 var icon = $(this);
  452.                 var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
  453.  
  454.                 if ($class in replacement)
  455.                     icon.attr('class', 'ui-icon ' + replacement[$class]);
  456.             });
  457.         }
  458.  
  459.         function enableTooltips(table) {
  460.             $('.navtable .ui-pg-button').tooltip({
  461.                 container : 'body'
  462.             });
  463.             $(table).find('.ui-pg-div').tooltip({
  464.                 container : 'body'
  465.             });
  466.         }
  467.  
  468.         $(document).one('ajaxloadstart.page', function (e) {
  469.             $.jgrid.gridDestroy(grid_selector);
  470.             $('.ui-jqdialog').remove();
  471.         });
  472.     });
  473. });
  474.  
  475. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement