jqGrid 的配置代碼

Phoenix Phoenix 2018.1.15 00:00 View(135) Comment (0)

項目里沒再用jqGrid,這段代碼不知道還有沒有用

var employeeIdCollection = 
 ($("#employeeIdCollection").length > 0)?$("#employeeIdCollection").val():"";
var departmentIdCollection = 
 ($("#departmentIdCollection").length > 0)?$("#departmentIdCollection").val():"";
myDefaultSearch = "cn",
getColumnIndexByName = function (columnName) {
       var cm = $(this).jqGrid('getGridParam', 'colModel'), i, l = cm.length;
       for (i = 0; i < l; i += 1) {
           if (cm[i].name === columnName) {
               return i; // return the index
           }
       }
       return -1;
   },
   modifySearchingFilter = function (separator) {
       var i, l, rules, rule, parts, j, group, str, iCol, cmi, cm = this.p.colModel,
           filters = $.parseJSON(this.p.postData.filters);
       if (filters && typeof filters.rules !== 'undefined' && filters.rules.length > 0) {
           rules = filters.rules;
           for (i = 0; i < rules.length; i++) {
               rule = rules[i];
               iCol = getColumnIndexByName.call(this, rule.field);
               cmi = cm[iCol];
               if (iCol >= 0 && ((typeof (cmi.searchoptions) === "undefined" ||
                     typeof (cmi.searchoptions.sopt) === "undefined")
                    && rule.op === myDefaultSearch) ||
                       (typeof (cmi.searchoptions) === "object" &&
                           $.isArray(cmi.searchoptions.sopt) &&
                           cmi.searchoptions.sopt[0] === rule.op)) {
                   // make modifications only for the 'contains' operation
                   parts = rule.data.split(separator);
                   if (parts.length > 1) {
                       if (typeof filters.groups === 'undefined') {
                           filters.groups = [];
                       }
                       group = {
                           groupOp: 'OR',
                           groups: [],
                           rules: []
                       };
                       filters.groups.push(group);
                       for (j = 0, l = parts.length; j < l; j++) {
                           str = parts[j];
                           if (str) {
                               // skip empty '', which exist in case of two separaters of once
                               group.rules.push({
                                   data: parts[j],
                                   op: rule.op,
                                   field: rule.field
                               });
                           }
                       }
                       rules.splice(i, 1);
                       i--; // to skip i++
                   }
               }
           }
           this.p.postData.filters = JSON.stringify(filters);
       }
   },
   dataInitMultiselect = function (elem) {
        setTimeout(function () {
            var $elem = $(elem), id = elem.id,
                inToolbar = typeof id === "string" && id.substr(0,3) === "gs_";
                options = {
                    selectedList: 2,
                    height: "auto",
                    checkAllText: "all",
                    uncheckAllText: "no",
                    noneSelectedText: "Any",
                    open: function () {
                        var $menu = $(".ui-multiselect-menu:visible");
                        $menu.width("auto");
                        return;
                    }
                };
            if (inToolbar) {
                options.minWidth = 'auto';
            }
            $elem.multiselect(options);
            $elem.siblings('button.ui-multiselect').css({
                width: inToolbar? "98%": "100%",
                marginTop: "1px",
                marginBottom: "1px",
                paddingTop: "3px"
            });
        }, 50);
    };
    
    $("#grid").jqGrid({
       url: "a-listDtAllDetails.action?uid=${attendance.attendanceId}&employeeIdCollection=" + 
       employeeIdCollection + "&departmentIdCollection=" + departmentIdCollection + "&mode=all",
       datatype: "json",
       mtype: "POST",
       colModel: [
		{name:'attendanceDetailsDayId',index:'attendanceDetailsDayId', 
                 width:60, sorttype:"int",label:"編號"},  
		{name:'name',index:'name', width:90,label:"用户名",stype: "select", 
                 searchoptions: { sopt: ["eq", "ne"], value: ":Any;1:Yes;0:No" }},  
       ],
       pager: "#gridpager",
       rowNum: 50,
       rowList: [50, 100],
       sortname: "attendanceDetailsDayId",
       sortorder: "asc",
       jsonReader:{  
           repeatitems : false ,
           cell:"",
           id:"0"
       }, 
       viewrecords: true,
       gridview: true,
       autoencode: true,
       autowidth:true,
       height:500,
      // beforeRequest: function () {
      //     modifySearchingFilter.call(this, ',');
       //}
       //caption: "My first grid",
   }).navGrid('#gridpager').jqGrid('filterToolbar',
           {stringResult:true, searchOnEnter:true, defaultSearch:myDefaultSearch});;
   
   $("#gs_closed").multiselect();

 

本文链接 https://www.mangoxo.com/blog/yKDgNpxR 版权所有,转载请保留地址链接,感谢!

Latest Comments :