Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

row selection via selectItem fails when grid is sorted and then a new row is added #348

Closed
sum4me opened this issue Apr 17, 2013 · 3 comments
Assignees
Milestone

Comments

@sum4me
Copy link

sum4me commented Apr 17, 2013

I have a grid of say 4 rows. I want to add a row to the data and have that row be automatically selected. to do this I added a listener to ngGridEventData event. when the data changes I perform a call to selectItem with the new item's index as the argument.

this works fine when the grid is not sorted.

but doesn't work as expected when grid was sorted before the new data item was added.
if the grid is sorted, and then a new data item is added to the grid's data source.
it correctly displays the newly added item in the correct sort order. however, it selects the wrong row when selecting the row via a call to selectItem (as described above).

I am using the latest build 2.0.4 . I looked at the code and noticed this was caused due to a bug in the sortActual method.

a snippet is shown below

self.sortActual = function() {
    if (!self.config.useExternalSorting) {
        var tempData = self.data.slice(0);
        angular.forEach(tempData, function(item, i) {
            var e = self.rowMap[i];
            if (e != undefined) {
                var v = self.rowCache[v];
                if(v != undefined) {
                    item.preSortSelected = v.selected;
                    item.preSortIndex = i;
                }
            }
        });

as you can see on the line
var v = self.rowCache[v];

the wrong variable is being used to index into rowCache.I believe it should in fact be
var v = self.rowCache[i];

as this was a minor issue, i felt lazy to make a pull request.

thank you for your great work.
ng-grid is an awesome tool.

@sum4me sum4me closed this as completed Apr 17, 2013
@sum4me sum4me reopened this Apr 17, 2013
@RichardAlan
Copy link

@sum4me - I opened a similar issue as I cannot find a way to add a new row and have it selected. Can you share some of the code that you have to add the new row.

@c0bra
Copy link
Contributor

c0bra commented Apr 22, 2013

Reference: #354.

@c0bra
Copy link
Contributor

c0bra commented Apr 22, 2013

I have a plunker demonstrating this issue with the code @RichardAlan supplied in #354: http://plnkr.co/edit/b58tAV (though I believe it should be selectItem(rowLen-1, true) ...

Once I get the the end-to-end tests set up, I will try to use the fix @sum4me suggested. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants