2014-06-11 56 views
0

這是我的jqgrid的JavaScript部分。主要的想法是根據我選擇的下拉列表中的值進行分組。在我的情況下,有兩個選項值(-1和「cerinte」)。當值爲-1時,我不想進行任何分組,但是當我選擇cerinte時,我想在「cerinte」之後進行探索。問題是我不得不按F5按鈕(刷新頁面),使其工作。之後當我刷新頁面時,它完美地工作。我可以做這個工作,而無需刷新頁面嗎? THX 我忘了提,我使用散列鏈接:我的鏈接看起來像: ...../TIMP#週期= 2014年6月11日& ddProject = -1 & ddUser = 48 & ddActivity = -1 & txTask = & ddGrupare = -1 &頁面= 1個& sortname =日期&排序順序= ASC如何在jQgrid中分組後刷新網格?

window.onhashchange = function() { 
     jQuery("#list2").trigger("reloadGrid"); 
    } 
    var url = $.url(window.location.href.replace("#","")); 
    var page = url.param("page"); 
    var sortname = url.param("sortname"); 
    var sortorder = url.param("sortorder"); 
    var group_check = url.param("ddGrupare"); 
    $("#ddGrupare > option").each(function() { // se selecteaza option dupa care s-a facut gruparea, valorea fiind selectata va fi atribuita la parametrul URL 
     if(group_check == this.value){ 
      $(this).attr("selected","selected"); 
     } 
    }); 
    if (group_check == "cerinte"){ 
     group_check = true; 
    }else{ 
     group_check = false; 
    } 

    jQuery("#list2").jqGrid({ 
     url:'/timp/json/',  
     datatype: "json", 
     colNames:['Data si ora','Durata','Utilizator','Proiect: task', 'Descriere lucru','',''], 
     colModel:[ 
      {name:'Data',index:'date',width:'11%'}, 
      {name:'Durata',index:'duration',width:'4%'}, 
      {name:'Responsabil',index:'username',width:'8%'},   
      {name:'Proiect',index:'projectname',width:'22%'}, 
      {name:'Descriere',index:'description',width:'40%'}, 
      {name:' ',index:'remove', sortable:false, width:'3%'}, 
      {name:'cerinte',index:'cerinte', hidden: true, sortable:false, width:'3%'} 
     ], 
     rowNum:15,  
     sortname: 'date', 
     viewrecords: true, 
     sortorder: "asc", 
     caption:"", 
     autowidth: true, 
     shrinkToFit: true, 
     width: '100%', 
     height: '100%', 
     altRows: true, 
     altClass: '', 
     loadComplete:function(request){ 

      //alert("Load complete"); 
      showRecorder(); 
      $("#paging").html(request.userdata.pager); 
      $("#total").html(request.userdata.suma); 
      $(".numb").click(function() { 
       $("#list2").trigger("reloadGrid", [{page:$(this).text()}]); 
      }); 
      registerOverlay(); 
      doPagination(); 
      showConfirm(); 
      formatUrl(); 
      setBackUrl(); 
      $("#empty").hide(); 
      if(request.total == 0) 
       $("#empty").show(); 

      $("tr td b").each(function(){ 
       if ($(this).text() == "null"){ 
        $(this).text("Taskuri neasociate cu cerinte") 
       } 
      }); 
     }, 

     beforeRequest:function() { 

      jQuery("#list2").jqGrid('hideCol', ["cerinte"]); 
      //parseUrl(); 
      var taskname = jQuery("#txTask").val();  
      var projectid = jQuery("#ddProject").val(); 
      var userid = jQuery("#ddUser").val(); 
      var type = jQuery("#ddActivity").val(); 
      var period = $("#period").val().split(" - "); 
      var startdate = period.length > 0 ? period[0] : ''; 
      var enddate = period.length > 1 ? period[1] : ''; 
      jQuery("#list2").jqGrid('setGridParam',{url:"/timp/json/?projectid="+projectid+"&userid="+userid+"&type="+type+"&taskname="+taskname+"&startdate="+startdate+"&enddate="+enddate}); 
     }, 
     forceFit : true,   
     grouping:group_check, // se seteaza dc enable/disable grupare 
     groupingView : { 
      groupField : ['cerinte'], 
      groupSummary : [true], 
      groupColumnShow : [true], 
      groupText : ['<b>{0}</b>'], 
      groupCollapse : false, 
      groupOrder: ['asc'], 
      groupHeader: [true], 
     } 
    }); 
     /*================================================================================*/ 
     /*        Grupare           */ 
     /*================================================================================*/ 

     $("#ddGrupare").change(function() { 
      var groupingName = $(this).val(); 
      url = $("#list2").jqGrid('getGridParam','url'); 
      url = url+"&ddGrupare="+groupingName; 
      jQuery("#list2").jqGrid('setGridParam',{url:url}); 
      if (groupingName != '-1') { 
       $("#list2").jqGrid('groupingGroupBy', groupingName); 
       $("thead").first().hide(); 

      }else{ 
       $('#list2').jqGrid('groupingRemove'); 
       $("thead").first().show(); 
      } 
      jQuery("#list2").trigger("reloadGrid"); 
     }); 
+0

那麼,有沒有人可以幫助我? :d – Chester

回答

0

Finnaly我得到了解決:

window.onhashchange = function() { 
    jQuery("#list2").trigger("reloadGrid"); 
} 
var url = $.url(window.location.href.replace("#","")); 
var page = url.param("page"); 
var sortname = url.param("sortname"); 
var sortorder = url.param("sortorder"); 
var group_checkk = url.param("ddGrupare"); 
$("#ddGrupare > option").each(function() { // se selecteaza option dupa care s-a facut gruparea, valorea fiind selectata va fi atribuita la parametrul URL 
    if(group_checkk == this.value){ 
     $(this).attr("selected","selected"); 
    } 
}); 

jQuery("#list2").jqGrid({ 
    url:'/timp/json/',  
    datatype: "json", 
    colNames:['Data si ora','Durata','Utilizator','Proiect: task', 'Descriere lucru','',''], 
    colModel:[ 
     {name:'Data',index:'date',width:'11%'}, 
     {name:'Durata',index:'duration',width:'4%'}, 
     {name:'Responsabil',index:'username',width:'8%'},   
     {name:'Proiect',index:'projectname',width:'22%'}, 
     {name:'Descriere',index:'description',width:'40%'}, 
     {name:' ',index:'remove', sortable:false, width:'3%'}, 
     {name:'cerinte',index:'cerinte', hidden: true, sortable:false, width:'3%'} 
    ], 
    rowNum:15,  
    sortname: 'date', 
    viewrecords: true, 
    sortorder: "asc", 
    caption:"", 
    autowidth: true, 
    shrinkToFit: true, 
    width: '100%', 
    height: '100%', 
    altRows: true, 
    altClass: '', 
    loadComplete:function(request){ 


     showRecorder(); 
     $("#paging").html(request.userdata.pager); 
     $("#total").html(request.userdata.suma); 
     $(".numb").click(function() { 
      $("#list2").trigger("reloadGrid", [{page:$(this).text()}]); 
     }); 
     registerOverlay(); 
     doPagination(); 
     showConfirm(); 

     setBackUrl(); 
     $("#empty").hide(); 
     if(request.total == 0) 
      $("#empty").show(); 

     $("tr td b").each(function(){ 
      if ($(this).text() == "null"){ 
       $(this).text("Taskuri neasociate cu cerinte") 
      } 
     }); 
     var url = $.url(window.location.href.replace("#","")); 

     $("#list2").jqGrid('groupingGroupBy', 'cerinte'); 
    }, 

    beforeRequest:function() { 

     jQuery("#list2").jqGrid('hideCol', ["cerinte"]); 
     //parseUrl(); 

     formatUrl(); 
     var taskname = jQuery("#txTask").val();  
     var projectid = jQuery("#ddProject").val(); 
     var userid = jQuery("#ddUser").val(); 
     var type = jQuery("#ddActivity").val(); 
     var period = $("#period").val().split(" - "); 
     var startdate = period.length > 0 ? period[0] : ''; 
     var enddate = period.length > 1 ? period[1] : ''; 
     jQuery("#list2").jqGrid('setGridParam',{url:"/timp/json/?projectid="+projectid+"&userid="+userid+"&type="+type+"&taskname="+taskname+"&startdate="+startdate+"&enddate="+enddate}); 
    },  
    grouping:true 
}); 
    /*================================================================================*/ 
    /*        Grupare           */ 
    /*================================================================================*/ 

    $("#ddGrupare").change(function() { 
     var groupingName = $(this).val(); 
     url = $("#list2").jqGrid('getGridParam','url'); 
     url = url+"&ddGrupare="+groupingName; 
     jQuery("#list2").jqGrid('setGridParam',{url:url}); 
     if (groupingName != '-1') { 
      $("#list2").jqGrid('groupingGroupBy', groupingName); 
      $("thead").first().hide(); 

     }else{ 
      $('#list2').jqGrid('groupingRemove'); 
      $("thead").first().show(); 
     } 
     jQuery("#list2").trigger("reloadGrid");  
    });