2013-12-20 36 views
0

我光滑的網格設置:Slickgrid更新並不一致

var records = []; 
    var grid; 
    var columns = [ 
     { id: "ServerName", name: "Server Name", field: "ServerName" }, 
     { id: "DVCurrent", name: "DV Current", field: "DVCurrent", editor: Slick.Editors.LongText }, 
     { id: "DVLast", name: "DV Last", field: "DVLast" }, 
     { id: "PYCurrent", name: "PY Current", field: "PYCurrent", editor: Slick.Editors.LongText }, 
     { id: "PYLast", name: "PY Last", field: "PYLast" }, 
     { id: "PDCurrent", name: "PD Current", field: "PDCurrent", editor: Slick.Editors.LongText }, 
     { id: "PDLast", name: "PD Last", field: "PDLast" } 
    ]; 

    var options = { 
     enableCellNavigation: true, 
     enableColumnReorder: false, 
     forceFitColumns: true, 
     autoEdit: false, 
     editable: true 
    }; 

和網格的建立:

grid = new Slick.Grid("#myGrid", records, columns, options); 

,從我的MVC控制器中獲取數據的功能:

function GetRecords() { 
     $.ajax({ 
      url: '@VirtualPathUtility.ToAbsolute("~/Home/GetRecords")', 
      dataType: 'json', 
      type: 'GET', 
      success: function (data) { 
       records = data; 
       grid.setData(records); 
       grid.invalidate(); 
      } 
     }); 
    } 

頁面加載時一切順利。數據被提取。問題發生在我點擊保存按鈕時,我想要網格再次更新:

$('#btnSave').click(function() { 
      $.ajax({ 
       url: '@VirtualPathUtility.ToAbsolute("~/Home/UpdateAllRecords")', 
       dataType: 'json', 
       contentType: "application/json", 
       type: 'POST', 
       data: JSON.stringify(grid.getData()), 
       success: GetRecords 
      }); 
     }); 

它根本沒有做任何事情。該操作在服務器端成功完成,但不會刷新,就像GetRecords永不運行一樣。沒有控制檯錯誤。

如果我重新加載頁面正在提取更新的數據。

回答

1

你可能會缺少這片:

// Refresh the new data rendered 
grid1.updateRowCount(); 
grid1.render(); 

如果不工作,你可以嘗試讓你的保存async:false,你應該檢查與螢火蟲新的數據集的結果。希望有所幫助..