第一次点击时JQgrid列排序工作?再次点击,即第二次不能正常工作?

时间:2014-09-19 06:03:26

标签: jquery jqgrid

我正在使用jqgrid的这个代码块,而对列标题进行排序时它只能运行一次,

<script type="text/javascript"   src="http://ajax.googleapis.com/ajax/libs/
    jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/ui.multiselect.js"></script>   

<script type="text/javascript" src="http://www.ok-soft-gmbh.com
/jqGrid/jquery.jqGrid-4.5.2/js/i18n/grid.locale-en.js"></script>       
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/
jqGrid/jquery.jqGrid-4.5.2/js/jquery.jqGrid.src.js"></script>



 <script type="text/javascript">
  //<![CDATA[
/*global $ */
/*jslint plusplus: true */
$(function () {
    "use strict";
    var mydata = [
            { id: "1",  invdate: "2007-10-21", 
    name:     "4708R_4360MCH5_4331_6_37_14_86_Lx2636(devicemode=1) ",   
    note: "3note note note",   
    amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
            { id: "2",  invdate: "2007-10-22", name: "4708R_4360MCH5_
 36(devicemode=1) ",  note: "3note2 note2",  amount: "300.00", tax: "20.00", 
  closed: false,   ship_via: "FE", total: "320.00" },
            { id: "3",  invdate: "2007-09-01", name: "test3",  note: "3note3 note3", 
   amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" }

        ];
         $("#list").on("jqGridSortCol", function (e, sortName, iCol, sortOrder) {
          $("table.ui-jqgrid-htable thead").remove("table#list");
        alert("sortName=" + sortName + "\niCol=" + iCol + "\nsortOrder=" + sortOrder);
        if (sortName === "name") {
            alert(sortOrder);
            var ord=sortOrder;
            alert(ord);

        }
    });


    // $("#list1").jqGrid("GridUnload")            
    $("#list").jqGrid({
        datatype: "local",
        data: mydata,
        colNames: ["Client", "Date", "Amount", "Tax", "Total", "Closed",
        "Shipped via", "Notes"],
        colModel: [
            { name: "name", editrules: {required: true} },
            { name: "invdate", align: "center"},
            { name: "amount" },
            { name: "tax" },
            { name: "total" },
            {name: "closed", align: "center", formatter: "checkbox",
                edittype: "checkbox", editoptions: {value: "Yes:No", defaultValue: "Yes"},
                stype: "select", searchoptions: { sopt: ["eq", "ne"],
            value: ":Any;true:Yes;false:No" } },
            {name: "ship_via", align: "center", formatter: "select",
                edittype: "select", editoptions: { value: "FE:FedEx;TN:TNT;
             IN:Intim", defaultValue: "FE" },
                stype: "select", searchoptions: { sopt: ["eq", "ne"], 
           value:    ":Any;FE:FedEx;TN:TNT;IN:Intim" } },
            { name: "note", sortable: false, search: false, edittype: "textarea" }
        ],
        rowNum: 10,
        rowList: [5, 10, 20],
        pager: "#pager",
        gridview: true,
        rownumbers: true,
        sortname: 'invdate',

        viewrecords: true,
        sortorder: "desc",
        shrinkToFit: false,
        height: "auto",
        viewsortcols:[true,"vertical",true]
    });

我包含了所有的js文件,我正在通过invdate进行排序,一次排序工作正常,第二次排序不起作用。任何人都可以帮我这个,

 $("#list1").on("jqGridAfterLoadComplete jqGridRemapColumns", function () {
                var $this = $(this),
                    $cells = $this.find(">tbody>tr>td"),
                    $colHeaders = $this.closest(".ui-jqgrid-view").find(">.ui-jqgrid-hdiv>.ui-jqgrid-hbox>.ui-jqgrid-htable>thead>.ui-jqgrid-labels>.ui-th-column>div"),
                    colModel = $this.jqGrid("getGridParam", "colModel"),
                    iCol,
                    iRow,
                    rows,
                    row,
                    n = $.isArray(colModel) ? colModel.length : 0,
                    cm,
                    colWidth,
                    idColHeadPrexif = "jqgh_" + this.id + "_";
                $cells.wrapInner("<span class='mywrapping'></span>");
                $colHeaders.wrapInner("<span class='mywrapping'></span>");

                for (iCol = 0; iCol < n; iCol++) {
                    cm = colModel[iCol];
                    colWidth = $("#" + idColHeadPrexif + $.jgrid.jqID(cm.name) + ">.mywrapping").outerWidth() + 25; // 25px for sorting icons
                    for (iRow = 0, rows = this.rows; iRow < rows.length; iRow++) {
                        row = rows[iRow];
                        if ($(row).hasClass("jqgrow")) {
                            colWidth = Math.max(colWidth, $(row.cells[iCol]).find(".mywrapping").outerWidth());
                        }
                    }
                    $this.jqGrid("setColWidth", iCol, colWidth);
                }

            });

这是整个代码

 $("#list1").on("jqGridAfterLoadComplete jqGridRemapColumns", function () {
                var $this = $(this),
                    $cells = $this.find(">tbody>tr>td"),
                    $colHeaders = $this.closest(".ui-jqgrid-view").find(">.ui-jqgrid-hdiv>.ui-jqgrid-hbox>.ui-jqgrid-htable>thead>.ui-jqgrid-labels>.ui-th-column>div"),
                    colModel = $this.jqGrid("getGridParam", "colModel"),
                    iCol,
                    iRow,
                    rows,
                    row,
                    n = $.isArray(colModel) ? colModel.length : 0,
                    cm,
                    colWidth,
                    idColHeadPrexif = "jqgh_" + this.id + "_";
                $cells.wrapInner("<span class='mywrapping'></span>");
                $colHeaders.wrapInner("<span class='mywrapping'></span>");

                for (iCol = 0; iCol < n; iCol++) {
                    cm = colModel[iCol];
                    colWidth = $("#" + idColHeadPrexif + $.jgrid.jqID(cm.name) + ">.mywrapping").outerWidth() + 25; // 25px for sorting icons
                    for (iRow = 0, rows = this.rows; iRow < rows.length; iRow++) {
                        row = rows[iRow];
                        if ($(row).hasClass("jqgrow")) {
                            colWidth = Math.max(colWidth, $(row.cells[iCol]).find(".mywrapping").outerWidth());
                        }
                    }
                    $this.jqGrid("setColWidth", iCol, colWidth);
                }

            });
   $("#list1").on("jqGridSortCol", function (e, sortName, iCol, sortOrder) {
                alert("sortName=" + sortName + "\niCol=" + iCol + "\nsortOrder=" + sortOrder);
                 //$("#list1").trigger("reloadGrid");

                var myorder=sortOrder;
                if (sortName === "idreleaseRequest") {
                    alert(sortOrder);
                    var ord=sortOrder;
                    alert(ord);

                }
            });

         $("#merror").text('');

        $("#list1").jqGrid("GridUnload")
        $("#list1").jqGrid({ url:"./controllers/apGetTestData.php?testanzres=1&testsuite="+testsuite+"&testcase="+testcase+"&ch="+ch+"&fromdate="+fromdate+"&todate="+todate+"&mmss="+mmss, datatype: 'xml', mtype: 'GET', height: 'auto',
        colNames:[ 'RRID', 'Release Tag','Completed Date','Result','Firm Ware','DUT','Summary','Remarks'],
        colModel:[

        {name:'idreleaseRequest', index:'idreleaseRequest', width:80, sorttype: 'int'},
        {name:'releaseRequestTag', index:'releaseRequestTag'},   
         {name:'DateInfo', index:'Date Info', sortable:true,align:'center'},
        {name:'Result', index:'Result', sortable:false},
        {name:'Firm Ware', index:'Firm Ware', sortable:false},
        {name:'DUT', index:'DUT', sortable:false},        

        {name:'Summary', index:'Summary', sortable:false, align:'left'} ,
         {name:'Remarks', index:'Total Suites', sortable:false}],       
        pager: $('#pager1'), rowNum:6, rowList:[6,12,18,24],

        sortname: 'idreleaseRequest',
        sortorder: "DESC",
        caption:"Test Results : "+ globalData,
        // caption:"Test Results ",
        sortable: true,
        shrinkToFit:true,
        autowidth: true,
        viewrecords: true,
         rownumbers:true,
         cloneToTop:true,
         hidedlg: true
    }).trigger('reloadGrid');
    $('#list1').jqGrid("setLabel", "rn", "SNo");

     document.getElementById("pdfgen").style.display = 'block';
    $("#list1").trigger("reloadGrid");
    }    
}

function  ShowHideColumn () {
                $.extend(true, $.ui.multiselect, {
                locale: {
                    addAll: 'Make all visible',
                    removeAll: 'Hide All',
                    itemsCount: 'Avlialble Columns'
                }
            });
            $.extend(true, $.jgrid.col, {
                width: 450,
                modal: true,
                msel_opts: {dividerLocation: 0.5},
                dialog_opts: {
                    minWidth: 470,
                    show: 'blind',
                    hide: 'explode'
                }
            });
          $("#list1").jqGrid("setColProp", "rn", {hidedlg: false});
         $('#list1').jqGrid('columnChooser',
         {
            done: function() {

          $("#list1").trigger("resize");
          $("list1").trigger("reload");
        }
         });


}

0 个答案:

没有答案