How to change the datasource on a YUI datagrid after creation


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'.

Best Solution

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

  {success: dataTable.onDataReturnInitializeTable},

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

Related Question