如何使用按钮刷新 YUI 数据表?

发布于 2024-07-14 17:22:30 字数 1214 浏览 6 评论 0原文

我正在测试脚本:

http://developer.yahoo.com/yui/examples/datatable /dt_xhrjson.html

我想添加一个按钮来刷新(重置)数据。 我会重置所有修改的数据并重新加载第一个数据。 我添加此代码,因此在选择(刷新)后,我没有数据:

YAHOO.util.Event.onContentReady("splitbuttonsfromjavascript", function () {

var onMenuItemSelect = function () {

        myDataTable.initializeTable();

        myDataTable.render();

        };

        var aSplitButton5Menu = [

            { text: "Refresh", value: 1, onclick: { fn: onMenuItemSelect } }

        ];

        var oSplitButton5 = new YAHOO.widget.Button({ type: "split",  label: "Refresh table", name: "splitbutton", menu: aSplitButton5Menu, container: this });

    });

我需要在 onMenuItemSelect 中使用什么来刷新 mydataTable?


我做了一些更改来修改示例中的“城市”和“评级”: http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson。现在

,我希望使用按钮重置 MyTable(并重新加载默认数据集)。 当我使用我的代码时,单击按钮后,我清除所有数据,并且默认数据不会重新加载(我有:“未找到记录。”单击按钮后)。

如何重新加载默认数据?

I'm testing the script:

http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html

I would like to add a button to refresh(reset) the data.
I would reset all modified data and reload first data.
I add this code, so after select (refresh), I have no data:

YAHOO.util.Event.onContentReady("splitbuttonsfromjavascript", function () {

var onMenuItemSelect = function () {

        myDataTable.initializeTable();

        myDataTable.render();

        };

        var aSplitButton5Menu = [

            { text: "Refresh", value: 1, onclick: { fn: onMenuItemSelect } }

        ];

        var oSplitButton5 = new YAHOO.widget.Button({ type: "split",  label: "Refresh table", name: "splitbutton", menu: aSplitButton5Menu, container: this });

    });

What I need to use in my onMenuItemSelect to refresh mydataTable?


I made some changes to modify the "city" and "rating" in the sample :
http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html

Now, I wish resetting MyTable with a button (and reload default dataset).
When I use my code, after button click, I clear all and default data are not reloaded (I have : "No records found." after button click).

How I can reload default data ?

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

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

发布评论

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

评论(5

萌能量女王 2024-07-21 17:22:30

我认为古尔诺的答案是最好的,但它缺少一点点。 为了显示“正在加载...”消息,您需要调用 showTableMessage 函数。

myDataTable.showTableMessage("Loading...");
myDataTable.getDataSource().sendRequest('', { success: myDataTable.onDataReturnInitializeTable, scope: myDataTable });

当请求完成后,onDataReturnInitializeTable函数会自动清除表消息。

我也将其发布在我的博客上。

I think Gourneau's answer is the best, but it is missing one nice touch. In order to get the 'Loading...' message to display, you need to make a call to the showTableMessage function.

myDataTable.showTableMessage("Loading...");
myDataTable.getDataSource().sendRequest('', { success: myDataTable.onDataReturnInitializeTable, scope: myDataTable });

When the request is finished, the onDataReturnInitializeTable function will automatically clear the table message.

I posted this on my blog as well.

若言繁花未落 2024-07-21 17:22:30

我无法让 Gourneau 发布的方法(到处都提到过)起作用,所以我想出了这个小技巧:

   function updateTable(){
      sortState = theDataTable.getState().sortedBy
      var sort = sortState ? sortState.key : "id";
      var dir = sortState ? sortState.dir : "yui-dt-desc";
      theDataTable.sortColumn(theDataTable.getColumn(sort),dir);
   };

找到当前的排序方法,然后调用 sortColumn 告诉它再次排序,它会刷新数据。 这也使分页保持有序。 我将其与搜索框和一些过滤器一起使用,这样我就可以更改它们的值并相应地更新表格。

I couldn't get the method that Gourneau posted (it's mentioned all over the place) to work, so i came up with this little hack:

   function updateTable(){
      sortState = theDataTable.getState().sortedBy
      var sort = sortState ? sortState.key : "id";
      var dir = sortState ? sortState.dir : "yui-dt-desc";
      theDataTable.sortColumn(theDataTable.getColumn(sort),dir);
   };

you find the current sort method, and then make a call to sortColumn telling it to sort again, and it refreshes the data. this keeps the pagination in order too. I use this with a search box and some filters so I can change their values and update the table accordingly.

才能让你更想念 2024-07-21 17:22:30

假设您有一个 DataTable 实例 myTable:

myTable.render() 将重绘表格;
myTable.initializeTable() 将清除所有状态,包括排序和选择,并重绘

-Eric

Assuming you have a DataTable instance myTable:

myTable.render() will redraw the table;
myTable.initializeTable() will blow away all state, including sorts and selections, and redraw

-Eric

孤独患者 2024-07-21 17:22:30

我认为如果你让按钮调用这个函数就会起作用:

myDataTable.getDataSource().sendRequest('',
{ success: myDataTable.onDataReturnInitializeTable,scope: myDataTable});

I think it will work if you have your button call this function:

myDataTable.getDataSource().sendRequest('',
{ success: myDataTable.onDataReturnInitializeTable,scope: myDataTable});
无声无音无过去 2024-07-21 17:22:30

我认为我无法在这里充分发布您所需的解决方案的所有代码,但是 Yahoo 的 Satyam(至少是 YUI 的主要贡献者)有一个重新查询方法,他已将其扩展添加到数据表中,并已发布举个例子。 我已经使用过它,并且它工作得非常好 - 特别是当您需要为表格提供搜索功能时。

这是一个开始的链接,但我还会在“Satyam requery”下搜索更多示例或更适合您的数据表版本的示例。

http://www.satyam.com.ar/yui/2.6.0 /requery.html

-Jason

p.s. 如果您使用服务器端数据,那么利用 onDataReturnInitializeTable 方法的解决方案会有所帮助,但我认为 Satyam 的解决方案也考虑了这一点,并跟踪您的分页。

I don't think I can adequately post all of the code here for your needed solution, but Satyam of Yahoo (a major contributor to YUI at least) has a requery method that he has added an extension for to the Datatable, and has posted example for it. I have used this, and it works beautifully - especially when you need a search function for your tables.

Here is a link to start with, but I would also search under "Satyam requery" for further examples or examples that fit more with your version of the datatable.

http://www.satyam.com.ar/yui/2.6.0/requery.html

-Jason

p.s. If you're using server-side data, then a solution that utilizes the onDataReturnInitializeTable method would help, but I think Satyam's solution accounts for this, also, as well as keeping track of your pagination.

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