2012-03-23 64 views
1

我正在爲IBM BusinessSpace創建窗口小部件,並且遇到了尋呼問題。 數據從數據庫中成功返回(使用restlet)並顯示在網格中。導航也顯示在網格下方(下一頁,上一頁,轉到頁面,頁數等)。 例如,如果我有3頁,每頁5行,並且想導航到第二頁,當我點擊第2頁時,數據重新加載(看起來像restlet被再次調用),並且前5行(顯示在第一頁上)也顯示在這一張上。如果我選擇其他導航選項(下一頁,...),則會發生同樣的情況。底線,每次點擊都會導致我數據庫的前5行。 關於如何解決此問題的任何線索?尋呼無法正常工作,在EnhancedGrid中使用JsonRest

下面是關於這個代碼:

dojo.require("dojo.data.ObjectStore"); 
dojo.require("dojox.grid.enhanced.plugins.Pagination"); 
dojo.require("dojox.grid.EnhancedGrid"); 
dojo.require("dojo.store.JsonRest"); 


var restStore = new dojo.store.JsonRest({target:"https://localhost:9443/Application/hello"}); 

var dataStore = dojo.data.ObjectStore({objectStore: restStore}); 

dojo.ready(function(){ 

    var grid = new dojox.grid.EnhancedGrid({ 

     store: dataStore, <br> 
     structure: [     
      {name:"Value", field:"value", width: "auto"}, 
      {name:"RequestID", field:"requestId", width: "auto"}, 
      {name:"ID", field:"id", width: "auto"}, 
      {name:"Name", field:"name", width: "auto"} 
     ],   
     columnReordering: true, 
     clientSort: true, 
     rowSelector: '20px', 
     rowsPerPage: 5, 
     autoHeight: true, 
     plugins: { 
      pagination: { 
       pageSizes: ["5", "10", "15", "All"], // page length menu options 
       description: true, // display the current position 
       sizeSwitch: true, // display the page length menu 
       pageStepper: true, // display the page navigation choices 
       gotoButton: true, // go to page button 
       position: "bottom" // position of the pagination bar 
      } 
     } 
    }, "gridDiv"); 
    grid.startup(); 
}); 
+0

請在這裏添加你的服務器端實現 – 2012-09-03 16:20:08

回答

2

當在網格中使用jsonRest,滾動時未顯示尚未加載的紀錄,在這一刻jsonRest使得對於需要顯示的數據的請求,爲了使這個傳呼機按預期工作,在你的休息實現中,你必須使用一個dojo創建的頭(範圍:0-24),這個是由dojo發送的,所以你知道所需數據的偏移和限制, ,您必須返回一個標題(Content-Range:項目0-24/66),這些數字可以告訴dojo從哪裏到哪裏顯示以及總記錄的數量。

這是在PHP(假設分貝和響應是實際對象)的一個例子:

$range = $request->headers->get('Range'); 

preg_match_all ('/.*?(\d+).*?(\d+)/is', $range, $matches); 

$limit = $matches[2][0]; 
$offset = $matches[1][0]; 

$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM table LIMIT {$limit} OFFSET {$offset}"; 
$result = $db->execute($sql); 

$sql2 = "SELECT FOUND_ROWS()"; 
$count = $db->execute($sql2); 

$response->setContent($result); 
$response->headers->set('Content-Range', "items $offset-$limit/{$count}"); 

在jsonRest documentation有一些信息。

+0

你知道是否有一種方法讓JsonRest實現延遲加載? – WoodenKitty 2013-10-30 05:50:37