2011-03-17 56 views

回答

1

唯一可能的解決方案是使用jQuery檢索: - 在「href」屬性從第一列標題,以獲得頁面數和 - 從「下一個頁碼」的「href」屬性來獲得對列和排序方向進行排序。

function reloadGrid(form) { 
    var grid = form._grid ? form._grid.value : "grid"; 
    var args = {}; 
    updateQueryParams(args, grid + " th a"); 
    args.sort = ""; 
    args.sortdir = ""; 
    updateQueryParams(args, grid + " tfoot a"); 
    args.page = 1; 

    for (var i = 0; i < form.elements.length; i++) { 
     var el = form.elements[i]; 
     if (el.type == "text" || el.type == "select" || (el.type == "radio" && el.checked)) 
      args[el.name] = el.value; 
     else if (el.type == "checkbox") 
      args[el.name] = el.checked; 
    } 

    //get controller name 
    var s = $("#grid th a")[0].onclick.toString(); 
    s = s.substring(s.indexOf("/")); 
    var controller = s.substring(0, s.indexOf("?")); 

    var queryString = ""; 
    for (var key in args) 
     queryString += "&" + key + "=" + escape(args[key]); 

    var url = controller + "?" + queryString.substring(1); 
    $("#" + grid).load(url + " #" + grid); 
} 


function updateQueryParams(args, path) { 
    var links = $("#" + path); 
    if (links.length == 0) 
     return; 

    var s = links[0].onclick.toString(); 
    s = s.substring(s.indexOf("?") + 1); 
    s = s.substring(0, s.indexOf(" #")); 

    var a = /\+/g; // Regex for replacing addition symbol with a space 
    var r = /([^&=]+)=?([^&]*)/g; 
    var d = function (s) { return decodeURIComponent(s.replace(a, " ")); }; 
    var q = s; 

    while (e = r.exec(q)) 
     args[d(e[1])] = d(e[2]); 
} 
相關問題