简体   繁体   English

如何将SlickGrid与Meteor.js反应式集合集成?

[英]How can I integrate SlickGrid with Meteor.js reactive collections?

SlickGrid focuses on displaying the data from a table or array, which is great. SlickGrid专注于显示表或数组中的数据,这很棒。 Meteor focuses on manipulating the data, but uses Minimongo. 流星专注于处理数据,但使用Minimongo。 How can SlickGrid integrate with Minimonogo collections and preserve its fast display and large data handling capabilities? SlickGrid如何与Minimonogo集合集成并保留其快速显示和大数据处理功能?

My current way of doing it feels wrong and is somewhat ugly. 我当前的操作方式感觉不对,而且有点难看。 I have a separate array for SlickGrid and writing some glue code to handle update events: 我为SlickGrid有一个单独的数组,并编写了一些粘合代码来处理更新事件:

  • Sorting: Handled by Meteor, triggers a full refresh (re-setting data) 排序:由流星处理,触发完全刷新(重置数据)
  • add/update/remove: figuring out the index and invalidating it 添加/更新/删除:确定索引并使之无效
  • Filtering: Handled by Meteor, triggers a full refresh (re-setting data) 过滤:由流星处理,触发完全刷新(重置数据)

How would I bind the Meteor data cursor directly to SlickGrid and handle only events with some glue code? 如何将流星数据光标直接绑定到SlickGrid并仅处理带有某些粘合代码的事件? Or can Slick.dataview be used? 还是可以使用Slick.dataview? The goal is to handle updates on a cell level. 目标是在单元级别上处理更新。

Using Slick.Dataview would only duplicate some functionality (sorting, filtering, CRUD..) of your collections but you should check it out to see how it interacts with Slick.Grid. 使用Slick.Dataview只会复制集合的某些功能(排序,过滤,CRUD ..),但是您应该检查一下以查看其如何与Slick.Grid交互。

If you look at Slick.Grid code you can see that it is only using 3 functions of Dataview .getLength() , .getItem() and .getItemMetadata() and last one is not mandatory to implement. 如果查看Slick.Grid代码,您会发现它仅使用Dataview .getLength() ,.getItem().getItemMetadata()的 3个函数,而最后一个不是强制实现的。 So Slick.Grid is basically 'View' component only reading 'Data' (Dataview) but where is the 'Controller'? 因此,Slick.Grid基本上是“视图”组件,仅读取“数据”(Dataview),但“控制器”在哪里?

Well you are to implement it actually and you can find one example in ' SlickGrid Example 4 '. 好吧,您实际上要实现它,并且可以在“ SlickGrid示例4 ”中找到一个示例。

Most important part of that example is in this snippet: 该示例中最重要的部分在以下代码段中:

  // wire up model events to drive the grid
  dataView.onRowCountChanged.subscribe(function (e, args) {
    grid.updateRowCount();
    grid.render();
  });

  dataView.onRowsChanged.subscribe(function (e, args) {
    grid.invalidateRows(args.rows);
    grid.render();
  });

This 2 events (onRowCountChanged, onRowsChanged) will get fired when you add, remove, update rows in Dataview and using there functions you are passing that information to Grid. 当您在Dataview中添加,删除,更新行并使用该函数将信息传递给Grid时,将触发这2个事件(onRowCountChanged,onRowsChanged)。

So basic idea is to do the same for your Mongo.Collection and as far as I can see Mongo.Cursor has .observeChanges() that is somewhat similar to .onRowsChanged 所以基本思路是对您的Mongo.Collection做同样的事情,据我所知Mongo.Cursor具有.observeChanges() ,它与.onRowsChanged有点相似

Checkout SlickGrid API in source at the end of document. 在文档末尾签出SlickGrid API。

To handle your Grid updates efficiently try using different invalidation methods .invalidate(All)Row(s)() and also .updateRow() and .updateCell() for even more precise control. 为了有效地处理Grid更新,请尝试使用不同的失效方法.invalidate(All)Row(s)()以及.updateRow().updateCell()进行更精确的控制。

These are mostly methods to handle view updates: 这些主要是处理视图更新的方法:

  "render": render,
  "invalidate": invalidate,
  "invalidateRow": invalidateRow,
  "invalidateRows": invalidateRows,
  "invalidateAllRows": invalidateAllRows,
  "updateCell": updateCell,
  "updateRow": updateRow,
  "getViewport": getVisibleRange,
  "getRenderedRange": getRenderedRange,
  "resizeCanvas": resizeCanvas,
  "updateRowCount": updateRowCount,
  "scrollRowIntoView": scrollRowIntoView,
  "scrollRowToTop": scrollRowToTop,
  "scrollCellIntoView": scrollCellIntoView,
  "getCanvasNode": getCanvasNode,
  "focus": setFocus,

If you need user interaction with you Grid subscribe to events and update your collection accordingly. 如果您需要与用户进行交互,则Grid可以订阅事件并相应地更新您的集合。

  "onScroll": new Slick.Event(),
  "onSort": new Slick.Event(),
  "onHeaderMouseEnter": new Slick.Event(),
  "onHeaderMouseLeave": new Slick.Event(),
  "onHeaderContextMenu": new Slick.Event(),
  "onHeaderClick": new Slick.Event(),
  "onMouseEnter": new Slick.Event(),
  "onMouseLeave": new Slick.Event(),
  "onClick": new Slick.Event(),
  "onDblClick": new Slick.Event(),
  "onContextMenu": new Slick.Event(),
  "onKeyDown": new Slick.Event(),
  "onAddNewRow": new Slick.Event(),
  "onValidationError": new Slick.Event(),
  "onViewportChanged": new Slick.Event(),
  "onColumnsReordered": new Slick.Event(),
  "onColumnsResized": new Slick.Event(),
  "onCellChange": new Slick.Event(),
  "onActiveCellChanged": new Slick.Event(),
  "onActiveCellPositionChanged": new Slick.Event(),
  "onDragInit": new Slick.Event(),
  "onDragStart": new Slick.Event(),
  "onDrag": new Slick.Event(),
  "onDragEnd": new Slick.Event(),
  "onSelectedRowsChanged": new Slick.Event(),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM