我能够利用slickGrid中的分页功能,但是我是jquery和slickGrid的新手,无法在页面之间移动。谁能帮我这个?任何帮助是极大的赞赏。谢谢!

$(document).ready(function() {var columns = [
{id:"counter", name:"#",field:"counter"},
{id:"data1", name:"Data 1",field:"data1"},
{id:"data2", name:"Data 2",field:"data2"},
{id:"data3", name:"Data 3",field:"data3"},
{id:"data4", name:"Data 4",field:"data4"}];

var options = { enableCellNavigation: false,
enableColumnReorder: false};

var FB_C_grid;
var FB_C_data;
var selectedRowIds = [];
var dataView;

$(function() {
FB_C_data = [];
FB_C_data[0]={"id":"0",
"data1":"test1",
"data2":"test1",
"data3":"test1",
"data4":"test1,
"counter":"1"
};

for (var i=1; i<50000; i++) {
    var d = (FB_C_data[i] = {});enter code here

    d["id"] = "id_" + i;
    d["data1"] = "data1_" + i;
    d["data2"] = "data2_" + i;
    d["data3"] = "data3_" + i;
    d["data4"] = "data4_" + i;
                d["counter"] = i;
   }


    dataView = new Slick.Data.DataView();
    dataView.setItems(FB_C_data);
    dataView.setPagingOptions({pageSize:20});
    FB_C_grid= new Slick.Grid($("#FB_C_sheet"),dataView.rows, columns,options);
    var pager = new Slick.Controls.Pager(dataView, FB_C_grid, $("#pagerTest"));

    dataView.onRowsChanged.subscribe(function(rows) {
 FB_C_grid.removeRows(rows);
 FB_C_grid.render();

         if (selectedRowIds.length > 0)
    {
     // since how the original data maps onto rows has changed,
     // the selected rows in the grid need to be updated
     var selRows = [];
     for (var i = 0; i < selectedRowIds.length; i++)
     {
      var idx = dataView.getRowById(selectedRowIds[i]);
      if (idx != undefined)
       selRows.push(idx);
     }

      FB_C_grid.setSelectedRows(selRows);
    }
   });

   dataView.onPagingInfoChanged.subscribe(function(pagingInfo) {
    var isLastPage = pagingInfo.pageSize*(pagingInfo.pageNum+1)-1 >= pagingInfo.totalRows;
                var enableAddRow = isLastPage || pagingInfo.pageSize==0;
                var options = FB_C_grid.getOptions();

                if (options.enableAddRow != enableAddRow)
         FB_C_grid.setOptions({enableAddRow:enableAddRow});
   });

               dataView.onRowCountChanged.subscribe(function(args) {
    FB_C_grid.updateRowCount();
                FB_C_grid.render();
   });

})

  });

最佳答案

当您尝试将jQuery对象传递到SlickGrid时,我看到了一些错误,而SlickGrid已经在后面的代码中使用了jQuery。创建SlickGrid对象时,只需要传递网格名称即可,因此在代码中,必须替换$("#pagerTest")而不将jQuery包装器变为"#pagerTest"
我看到您在2个不同的位置使用相同的名称,因此将您的2行替换为:

FB_C_grid= new Slick.Grid("#FB_C_sheet",dataView.rows, columns,options);
var pager = new Slick.Controls.Pager(dataView, FB_C_grid, "#pagerTest");


希望能帮助您使其正常工作...

关于javascript - 在slickGrid中分页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4846415/

10-13 03:20