문제

We're using a lot of YUI data tables to display data, and rather than using the built-in pagination we've done our own so we can paginate on the server side using AJAX without downloading the whole data set (which is often huge).

Whenever we use the data table's sorting funcionality, though, it will only sort the one page because from YUI's point of view that's the entire data set.

I need to be able to call an arbitrary function to reload the page data whenever the user tries to sort the data. I've looked into DataTable's sortFunction parameter and it's not ideal because it gets called multiple times (once for each row combination it needs) and I need to do it just once.

There are probably plenty of hacky ways I could do this, but what's the "nicest" way of going about this?

도움이 되었습니까?

해결책

Ideally, you would sort on the server side.

when create the datatable, one of the config options is generateRequest (see this example: http://developer.yahoo.com/yui/examples/datatable/dt_bhm.html )

generateRequest is a meant to be a function which generates a URL which returns the correct data set with which to fill the table. You probably have this.

For me, whenever I click on the column header (to sort), it makes a new request to the server, getting the correct page of sorted data.

다른 팁

Why not write a custom function and close over a variable that tracks whether it's been called?

var hasBeenCalled = false;
function mySortFunction(){
   if(!hasBeenCalled){
       // do something
       hasBeenCalled = true;
   }
}

Then replace the sortFunction with that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top