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

Primary key for rowEditable and index number of the row #5509

Closed
ivanovla opened this issue Jul 25, 2019 · 8 comments
Closed

Primary key for rowEditable and index number of the row #5509

ivanovla opened this issue Jul 25, 2019 · 8 comments
Assignees

Comments

@ivanovla
Copy link

  1. Can i use rowEditable without primary key, or in role primary key use array index?
  2. Can i show index number row for table in according array index, or i should add index in work array in role primary key?

Because i want show index in row for user and i dont want insert him in my work data every time in my component, and users should see at the index row

@ivanovla ivanovla changed the title Primary key for rowEditable and index number row Primary key for rowEditable and index number for row Jul 25, 2019
@ivanovla ivanovla changed the title Primary key for rowEditable and index number for row Primary key for rowEditable and index number of the row Jul 25, 2019
@Lipata Lipata self-assigned this Jul 25, 2019
@Lipata
Copy link
Member

Lipata commented Jul 25, 2019

  1. It is mandatory to set the primary key when having row editing. Please, read here.
  2. I guess you want to replace the checkbox with index and to be able to select clicking the index column? We are now working on a custom template for row selection Custom template for row selection checkbox #4998.

@ivanovla
Copy link
Author

  1. I read this documentation. I mean that the index of the work array is a primary index. I suppose that it is wrong to use internal work data(id from db) as primary key of table row(at least in my cases. It is definitely wrong).

  2. No, i would like to use index and checkbox the same time.

image

This is my example with custom table

@Lipata
Copy link
Member

Lipata commented Jul 25, 2019

Having the chance to template the row selection column, you can put whatever you want - which means in that case you can put index and checkbox at the same time and also you can put index that is not bound to the data source. By default, if you want to show row selector, it will be still only a checkbox, which means that if you want to overwrite it (like the demo above), you will need to put manually the checkbox again, in addition to the other things you want to show in the row selection column (in your case - the index).

@ivanovla
Copy link
Author

ivanovla commented Jul 25, 2019

I do not want to insert an index into the same column where the checkbox is located. I dont want to generate a unique index every time when I receive new data (filtering, sorting), but it looks like there is no choice now. In working with tables, it may often be necessary to have a ordinal row number, which you can add by parameter in configuration igxGrid (how with rowSelectable) in a cycle of drawing virtual tables. Igx itself calculates and inserts the lines and it can also add a sequence number. He can also add a row index by parameter in order not to change data from the server to the client and not to do an empty job of inserting the: index = workArray[i] + 1.

workArray = [{name: 'Ben'}, {name: 'John'}];
To display the sequence number I have to do:
workArray = workArray.map((e, index) => ({...e, id: index+1}));

But the igx itself can do it by parameter, because it is a sequence number. It uses everywhere. Example below

image

@ChronosSF
Copy link
Member

ChronosSF commented Jul 25, 2019

Rows in the grid have an index property that can be used in templates:

<igx-column [header]="'Index'">
     <ng-template igxCell let-cell="cell">
          {{cell.row.index + 1}}
     </ng-template>
</igx-column>

It'll however include group rows. If you use grouping but don't want group rows included you can use the solution in this issue: #5398

@ivanovla
Copy link
Author

ivanovla commented Jul 25, 2019

It's cool, it's work, without filter param([allowFiltering]="true"). If i add this param i get empty table with error, but without index column, i get not empty table with error. It seems like its the same problem as in #5495. But if we are using filterMode='excelStyleFilter' everything is working, but i cant use this filterMode because of this task #5448 is not done.

One question. Can i use this 'Index' as Primary key for row edit (rowEditable)?

@Lipata
Copy link
Member

Lipata commented Jul 25, 2019

The primary key is something that is coming from the database and you cannot put a templated column as a primary key.

What you can do is set grid's primary key (taking it from the database), but don't define a column for it and it will not show in the grid. At the same time, you can use the cell template @ChronosSF shown above and define your index column.

@ivanovla
Copy link
Author

Yes, that's a good idea, thanks. May add description to documentation by primary key (that may be using key not showing in the grid).
Now editing the line works correctly.
Decision @ChronosSF I can not use it until I figure out error #5495

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