tochoromero / aurelia-table

Simple functional data table for Aurelia
https://tochoromero.github.com/aurelia-table
MIT License
67 stars 25 forks source link

Select currentPage based on $isSelected #5

Closed rmja closed 8 years ago

rmja commented 8 years ago

Hi,

I am trying to select the currentPage so that it displays a particular item:

        let index = 0;
        for (let item of this.items) {
            item.$IsSelected = item.id === toDisplayItemId;
            if (item.$IsSelected) {
                this.currentPage = Math.floor(index / this.pageSize) + 1;
            }
            index++;
        }

This works perfectly in the simple case, but when column sorting is applied, this of cause selects the wrong page because this.items is the unmodified data bound with data.bind. Based on https://github.com/tochoromero/aurelia-table/blob/master/src/au-table.js#L78 it would be interresing to somehow have access to localData after filter and sort is applied, but before pagination is applied.

tochoromero commented 8 years ago

I have been going back and forth about how to implement this, and I think I have finally settled. I'm going to provide an API for the au-table element that will expose some methods; one of them will be: revealItem(item). If pagination is enabled it will reveal the page that contains the provided item. The only caveat will be if the item you want to reveal is not visible because of a filter... I'm not sure if I want to have the au-table directly clean the filter... Maybe we can have a second boolean parameter to force the reveal, meaning any filters will be cleared... on any case you could clean the filter yourself.

I hope I get a chance to implement this in the next couple of days.

rmja commented 8 years ago

Sounds fine to me. Maybe, instead of having a second force parameter, revealItem(item) could return a boolean telling weather the item was in fact revealed. If false, then the one can clear the filter and call revealItem(item) again, and tell the user that the filter was cleared.

tochoromero commented 8 years ago

Yeah, returning a boolean sounds good, thanks for your suggestions.

tochoromero commented 8 years ago

I have the fix in place, not I need to update the documentation. FYI for the next release I'm renaming the $IsSelected property to $isSelected to adhere to standards.

tochoromero commented 8 years ago

I have updated the documentation to include the Api