2017-04-04 42 views
0

這裏是我的JSP代碼爲JS網格dyanamically通過Js-grid獲取數據,但過濾不起作用?

$(function() { 

     $.ajax({ 
      type : "GET", 
      url : "/Final/Reports?value=2016-03-03&value2=2017-03-03" 
     }).done(function() { 

      $("#jsGrid").jsGrid({ 
       height : "auto", 
       width : "100%",   
       filtering: true, 
        sorting : true, 
       paging : true, 
       autoload : true, 
       pageSize : 3, 
       controller : { 
        loadData : function(filter) { 
         return $.ajax({ 
          type : "GET", 
          url : "/Final/Reports?value=2016-03-03&value2=2017-03-03", 
          data : filter 
         }); 
        }, 
       }, 
       fields : [ { 
        name : "patientId", 
        type : "text", 
        width : 150 
       }, { 
        name : "patientName", 
        type : "text", 
        width : 150 
       }, { 
        name : "genderId", 
        type : "number", 
        width : 150 
       }, { 
        name : "mobile", 
        type : "number", 
        width : 150 
       }, { 
        type : "control" 
       } ] 
      }); 

     }); 
    }); 

我新的JS網格和我拿來使用servlet數據,它是在網格中。但我不知道如何過濾數據。

任何想法?

回答

0

客戶端過濾和服務器端過濾完全在 肩上的開發人員。在loadData 控制器的方法中實現的客戶端過濾。服務器端顯然使用接收過濾參數的服務器 腳本實現,並使用它們獲取 數據並傳遞給客戶端。

這就是爲什麼您可以同時使用客戶端和服務器端過濾。下面是你的 controller.loadData方法可能看起來像在這種情況下:

loadData: function(filter) { 
    var d = $.Deferred(); 

    // server-side filtering 
    $.ajax({ 
     type: "GET", 
     url: "/items", 
     data: filter, 
     dataType: "json" 
    }).done(function(result) { 
     // client-side filtering 
     result = $.grep(result, function(item) { 
      return item.SomeField === filter.SomeField; 
     }); 

     d.resolve(result); 
    }) 

    return d.promise(); 
} 

的來源問題:https://github.com/tabalinas/jsgrid/issues/32

+0

感謝ü@tabalin我們實現了客戶端過濾。 –

相關問題