创建后如何更改 YUI 数据网格上的数据源

发布于 2024-07-25 05:36:54 字数 841 浏览 1 评论 0原文

我正在使用 Yahoo DataTable ,其 API 是 此处

一旦我渲染了网格一次,我就很难更改数据。 我正在使用 jQuery 通过 AJAX 获取数据,或者从客户端数据岛获取数据,并且需要将其放回网格中。

DataTable API 中没有 setDataSource 方法,并且更改“dataSource.liveData”不会更新网格。

 // does not work
 dataTable.dataSource.liveData = [ {name:"cat"}, {name:"dog"}, {name:"mouse"};

我的代码所基于的示例是基本 LocalDataSource 示例

如何更新数据源而不必完全重新创建表。 我不想使用进行异步调用的 YUI 数据源。 我需要知道如何“手动”执行此操作。

I am using the Yahoo DataTable for which the API is here.

I am having difficulty changing the data once I have rendered the grid once. I am using jQuery to get data via AJAX, or from a client side data island and need to put this back into the grid.

There is no setDataSource method in the DataTable API, and changing 'dataSource.liveData' does not update the grid.

 // does not work
 dataTable.dataSource.liveData = [ {name:"cat"}, {name:"dog"}, {name:"mouse"};

The example I am basing my code on is the basic LocalDataSource example.

How can I update the data source without having to completely recreate the table. I do NOT want to use the YUI datasources that make Async calls. I need to know how I can do this 'manually'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

朱染 2024-08-01 05:36:54

您走在正确的轨道上,您只是忘记告诉数据源将数据发送到数据表。 假设您使用的是 LocalDataSource 并希望用数据源中的数据替换表中的数据,替换 livedata 后您只需执行

dataTable.getDataSource().sendRequest(null,
  {success: dataTable.onDataReturnInitializeTable},
  dataTable);

另请参阅 onDataReturnXXX 方法API 参考中的 code>DataTable。 您可以附加新数据而不是替换等。

You were on the right track, you just forgot to tell the datasource to send the data to the datatable. Assuming you are using a LocalDataSource and want to replace the data in the table with what is in the datasource, after replacing livedata you just do

dataTable.getDataSource().sendRequest(null,
  {success: dataTable.onDataReturnInitializeTable},
  dataTable);

Also see the other onDataReturnXXX methods of DataTablein the API reference. You can append the new data instead of replacing, etc.

嗼ふ静 2024-08-01 05:36:54

我只是想补充一点,如果在参数属性中传递对 getState() 的调用,则可以保留分页。

dataTable.getDataSource().sendRequest(null,
    {
        success: dataTable.onDataReturnInitializeTable,
        argument: dataTable.getState()       
    }
);

I just wanted to add that you can preserve pagination if pass in a call to getState() in the argument property.

dataTable.getDataSource().sendRequest(null,
    {
        success: dataTable.onDataReturnInitializeTable,
        argument: dataTable.getState()       
    }
);
撞了怀 2024-08-01 05:36:54

如何更新数据源而无需完全重新创建表?

您的意思是不使用“新”声明吗? 如果是这样,我自己就不必这样做,但我经常使用 YUI。 我注意到有一个deleteRows方法,您可以使用它来删除所有行,从0到表的长度,然后使用addRows,它接受像您这样的文字数组和索引0,在本例中。

你试过这个吗?

编辑:看看这个示例。 你想做的事情绝对可以做到。 该表正在使用 setInterval 方法以设定的时间间隔在本地更新(这并不奇怪)。 看一下 setInterval 的作用,您可以看到它在数据源的实例上调用 makeConnection。 该方法听起来像是在进行远程调用,但其实不然。

让我们看一下示例中的几行。

    // Set up polling
    var myCallback = {
        success: myDataTable.onDataReturnInitializeTable,
        failure: function() {
            YAHOO.log("Polling failure", "error");
        },
        scope: myDataTable
    }
    myDataSource.setInterval(5000, null, myCallback)

最后一行可以被调用一次(或者根据需要按需调用),而不是像这样重写它以一定的间隔调用

myDataSource.makeConnection(null, myCallBack)

: widget.DataTable.html#method_onDataReturnInitializeTable" rel="nofollow noreferrer">onDataReturnInitializeTable 方法 - 我想你可以直接调用它,这会更有意义。

不管怎样,只要按照示例操作,去掉不需要的部分即可。 最终看来 onDataReturnInitializeTable 方法是关键。

希望有帮助。

How can I update the data source without having to completely recreate the table?

Do you mean without using a "new" statement? If so, I haven't had to do this myself, but I use YUI often. I notice that there is a deleteRows method which you could use to delete all the rows, 0 thru the length of the table, and then use the addRows which takes a literal array like yours and an index, 0, in this case.

Have you tried this?

Edit: Take a look at this example. What you want to do can definitely be done. The table is being updated locally at a set interval using the setInterval method (not suprisingly). Taking a look at what setInterval does, you can see that it calls makeConnection on the instance of the data source. The method sounds like it's making a remote call, but it's not necessarily.

Let's take a look at a couple lines from the example.

    // Set up polling
    var myCallback = {
        success: myDataTable.onDataReturnInitializeTable,
        failure: function() {
            YAHOO.log("Polling failure", "error");
        },
        scope: myDataTable
    }
    myDataSource.setInterval(5000, null, myCallback)

the last line could be called once (or on demand as you need) instead of at an interval by rewriting it like this:

myDataSource.makeConnection(null, myCallBack)

which calls the onDataReturnInitializeTable method - which i guess you could call directly which would make more sense.

Anyway, just follow along the example and take out the parts that you don't need. Ultimately it looks like the method onDataReturnInitializeTable is key.

Hope that helps.

沙沙粒小 2024-08-01 05:36:54

实际上,为了让它工作,我所做的就是以下两行代码(我的代码是从ajax返回的,所以与OP有点不同)......

dataTable.dataSource.liveData = eval(o.responseText);
dataTable.load({});

因为如果你读什么 datatable.load() 所做的是每个人都建议调用的内容。

Actually, all I did to get it to work is the following two lines of code (and mine was returned from ajax so a little different than the OP)...

dataTable.dataSource.liveData = eval(o.responseText);
dataTable.load({});

because if you read what datatable.load() does is what everyone was suggesting to call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文