How can I refresh a YUI dataTable with a button?

为君一笑 提交于 2019-12-05 04:21:48

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.

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.

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

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

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!