javascript 光滑网格中的数据更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9772207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:47:35  来源:igfitidea点击:

Data Update in Slick Grid

javascriptjqueryslickgrid

提问by javanes

I have a slickgrid, with about 100 rows. Its data is refreshed in 5 seconds, but it is disturbing at each update the scroll is reset. I have tried to use dataview and dataview.refresh() but this time no change is reflecte to grid.

我有一个 slickgrid,大约有 100 行。它的数据会在 5 秒内刷新,但每次更新都会干扰滚动重置。我曾尝试使用 dataview 和 dataview.refresh() 但这次没有更改反映到网格。

Here what I tried at each refresh:

这是我在每次刷新时尝试的内容:

mapMemoryTableDataView.beginUpdate();
mapMemoryTableDataView.setItems(data);
mapMemoryTableDataView.endUpdate();
mapMemoryTableDataView.refresh();

if(mapMemoryTableGrid == null)
    mapMemoryTableGrid = new Slick.Grid("#datatableMap1", mapMemoryTableDataView, columns, options);

mapMemoryTableGrid.updateRow(1)
mapMemoryTableGrid.render()

采纳答案by javanes

I have called the following

我打电话给以下

 mapMemoryTableDataView.beginUpdate();
    mapMemoryTableDataView.setItems(data);
    mapMemoryTableDataView.endUpdate();
    mapMemoryTableDataView.refresh();
    for (var i = 0; i < olist.length; i++) {
        mapMemoryTableGrid.updateRow(i)
    }

invalidate and refresh did not cure my problem.

无效和刷新并没有解决我的问题。

回答by Jibi Abraham

You should definitely try the invalidatemethod

你一定要试试这个invalidate方法

grid.invalidate();

From personal experience, all you need to do to refresh the grid is to use the invalidatemethod, provided on the grid. This updates everything and also preserves the scroll.

根据个人经验,刷新网格所需要做的就是使用网格上invalidate提供的方法。这会更新所有内容并保留滚动条。

And by refresh, do you mean you are replacing the data, or updating certain rows?

通过刷新,您的意思是要替换数据还是更新某些行?

回答by Grey Wolf

just use

只是使用

gridItems.invalidate();
gridItems.render();

invalidate: mean nead to validate which row you want - in this case: no parameter row id = all row

无效:意味着需要验证您想要的行 - 在这种情况下:无参数行 ID = 所有行

回答by juanchoelx

I have called the following code:

我调用了以下代码:

        mapMemoryDataView.beginUpdate();
        mapMemoryDataView.setItems(pointsRows, "id");
        mapMemoryDataView.endUpdate();
        mapMemoryDataView.syncGridSelection(pointsGrid, false);

        for (var i = 0; i < pointsRows.length; i++) {
            mapMemoryTableGrid.updateRow(i);
        }

        mapMemoryTableGrid.invalidate();
        mapMemoryTableGrid.render();

回答by Dominik Ras

What worked for me was:

对我有用的是:

    events[v_current_row_num].field_id = v_new_field_id;
    events_grid.updateRowCount();
    events_grid.render();

I am using different grid and view names, but the concept revolved around calling updateRowCount and render functions.

我使用了不同的网格和视图名称,但这个概念围绕着调用 updateRowCount 和渲染函数。