swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

not getting rowIndex in rowdetails #992

Open WalkOffEarth opened 7 years ago

WalkOffEarth commented 7 years ago

while implementing edit functionality to row details not getting rowIndex.

osamasaeed commented 7 years ago

facing the same problem even not in editing mode

BearandYoon commented 7 years ago

I am facing the same issue. @WalkOffEarth , @osamasaeed Do you have a solution for this issue?

Inlesco commented 6 years ago

Encountered the same issue.

Previously, I've used 9.3.1 version and now just updated to the most recent one - 10.2.3 - and I'm facing this issue.

Before 10.2.3, each row object passed to any of the event handler callbacks had $$index property as mentioned here - https://swimlane.gitbooks.io/ngx-datatable/api/table/internals.html

But now, it's gone... Anybody found any alternatives to this? This is a crucial, software-breaking bug.

wizarrc commented 6 years ago

@WalkOffEarth have you tried let-rowIndex="rowIndex" in the following example:

        <!-- Row Detail Template -->
        <ngx-datatable-row-detail [rowHeight]="100" #myDetailRow (toggle)="onDetailToggle($event)">
          <ng-template let-rowIndex="rowIndex" let-row="row" let-expanded="expanded" ngx-datatable-row-detail-template>
            <div style="padding-left:35px;">
              <div><strong>Address</strong></div>
              <div>{{row.address.city}}, {{row.address.state}}</div>
            </div>
            <div>row index: {{rowIndex}}</div>
          </ng-template>
        </ngx-datatable-row-detail>
BearandYoon commented 6 years ago

@Inlesco rowIndex works on version 9.3.1? I just updated to version 9.3.1 but it doesn't work for me.

Inlesco commented 6 years ago

@BearandYoon no, rowIndex does not work on 9.3.1, thus, why I decided to update.

I was referring to $$index property being part of rowItem object that's, f.e., onSelect callback's payload.

wizarrc commented 6 years ago

FYI, $$index was removed in 10.0.0, but rowIndex wasn't added to rowDetails till version 10.0.2.

BearandYoon commented 6 years ago

@wizarrc Thanks for your reply. So which version should I use for a rowIndex?

wizarrc commented 6 years ago

@BearandYoon version 10.0.2+ should work. check the changelog for details on features/bugfixes you are looking for.

BearandYoon commented 6 years ago

Hi @wizarrc rowIndex is working for me. Thanks. 👍

I have another issue on ngx-datatable(inline-editing). gurnui

As you can see, I have several sub-rows(https://go.gurn.io/test, https://go.gurn.io/test) in a table row. When I change first sub-row, second sub row also is changed. For ex: I changed https://go.gurn.io/test to https://go.gurn.io/test1, and choose the another element. then second sub-row also is changed to https://go.gurn.io/test1.

I guess it is ngx-datatable issue. Do you have a solution for this issue? Thanks.

Inlesco commented 6 years ago

@wizarrc Hey!

Regarding FYI, $$index was removed in 10.0.0, but rowIndex wasn't added to rowDetails till version 10.0.2., I'd like to ask - how to get the index of a row now in the onSelect or any other callback's you provide for ngx-datatable component?

Example:

(activate)="allowRowSelection ? onActivate($event) : false" (select)='onSelect($event)'

Basically, I want onSelect args to contain a rowIndex of some sort and since you've removed $$index from the row object supplied in the callback by default, I don't see any other clean way, except for managing indexes on your own.

Also, could you please update this - https://swimlane.gitbooks.io/ngx-datatable/api/table/internals.html - since $$index is removed (unless I misunderstood something)?

wizarrc commented 6 years ago

I'd like to ask - how to get the index of a row now in the onSelect or any other callback's you provide for ngx-datatable component?

@Inlesco As far as I know, the maintainers of the project are the employees of the Swimlane company. I don't provide anything at the moment and I did not remove $$index from the project, though I was in favor of it. I am working on a forked copy of the project for a personal project of mine, but right now I contribute some code fixes and have been answering some questions on here. I've been arguing the same thing that you suggest with other callbacks.

Refer here on a conversation I had about how to change the selected property and the corresponding event to be more useful.

This is an open source project, so feel free to open up issues on here with bugs you find or feature requests you want. Also, if you got value out of the project, consider forking the project and contributing changes for consideration by the project maintainers. That's what I did earlier this year.

wizarrc commented 6 years ago

@BearandYoon I have no idea. Do you have a plunker demo?

Inlesco commented 6 years ago

@wizarrc

sorry, confused you with the primary repo contributors. it's pretty sad that there's no deprecation warnings or anything when such modifications are being made. it'd be great if they added console.warns on a new version (toggleable, of course), especially if there's breaking changes in the API.

otherwise, the user of the package has to waste tons of time searching for solutions, comparing his local package version to the one in the official examples, even to pull the official ver. to this system, run it on localhost and observe things.

i'd gladly contribute on this if I had enough time. i may have some time in a couple of weeks later, we'll see.

wizarrc commented 6 years ago

@Inlesco The reason there is no deprecation warning is:

  1. This is a small project compared to say Angular. From the looks of it, it's completely spare time contributions.
  2. It was a breaking change, thus raising the major version number.
  3. To create a shadow $$index for the sake of compatibility would be a much larger task, possibly contain bugs, and make the table slower (though very minor) due to double accounting.
  4. The whole point of removing $$index was to make it immutable, so the point was the actual feature people requested. So suggesting adding it back would break people who are using version 10+ depending on their collection not being modified by the library.

I agree that the correct move for such limiting factors was to make a clean break. The good news in all that, it that your project wont auto upgrade you to a major version number, and when you do upgrade, you are expected to see what the breaking changes are and adjust your project accordingly, which should be very minor since a table is probably a small component in a larger project, unlike say Angular, where they must be very careful, because projects are built entirely using their library/framework.

stephencawood commented 6 years ago

I had to work around this issue by creating a hidden column and copying the rowIndex into that column. It's hacky and I'd appreciate having rowIndex in rowDetails back.