hjalmers / angular-generic-table

A generic table for Angular 2+. Generic table uses standard markup for tables ie. table, tr and td elements etc. and has support for expanding rows, global search, filters, sorting, pagination, export to CSV, column clicks, custom column rendering, custom export values.
https://hjalmers.github.io/angular-generic-table/
MIT License
104 stars 55 forks source link

Index number of row #208

Open vaydich opened 6 years ago

vaydich commented 6 years ago

Hello!

How can i get the index of row? Or how can i build it according pagination?

hjalmers commented 6 years ago

Hi @vaydich, perhaps you can elaborate a bit on what you're trying to accomplish and what you need the index for? When the data is added, generic-table adds a unique id for every row which could be used to get the index but it's the index of the original sort and filter order so it won't update. There's also a property exposed on the table called gtInfo that holds some information, see the wiki for more info. The gtInfo is also emitted as an event when the table info changes.

vaydich commented 6 years ago

I need just to add index number of row (1, 2, 3, 4 ...). I can make it by some counter but i don't have acces to loop of rows. About this "There's also a property exposed on the table called gtInfo that holds some information": it's not working with lazy

hjalmers commented 6 years ago

Well if you're using lazy loading I guess you're returning the data in batches and the server should know the order and the index of the rows that are returned. One option could be to add order/index as a separate column (that could be hidden too) like in this example. It would also be possible to create a new column and generate a index for the row using the value function and just bump a number for every row that is rendered.

Here's another example of how you could do it:

screenshot 2018-04-12 23 13 40

It might be that I've misunderstood what you're trying to do, I guess we could always add an index number like a row property (just like $$rowId), not sure what anyone would like to use it for though...

vaydich commented 6 years ago

Thank you. But what if i haven't any special fields (like "order") that i can use for ordering (first row, second row ...) in response array of objects from server. I have only index of array. But i can't get the row index (array index) of configObject.data array in row object when trying to render: render: (row) => { // there is no any index (only id) }

Now i see only one way - mapping data from server and add something like "order" to each object. But it's bad i think...

hjalmers commented 6 years ago

I might be able to create an example for you, would it suffice to get the index of the visible rows only or do you need the index of all the records? Let's say that you load page one from the server and display 10 records, they would have indexes from 1 to 10. Would page two need to have 11 to 20 or do you still want 1 to 10 (that's what's visible to the table as it's only loading 10 records at a time unless you've specified something else when lazy loading)?

vaydich commented 6 years ago

Thank you for suggestion to create an example. It will be nice. I need like this - 1-10, 11-20, 21-30 ...

vaydich commented 6 years ago

up

hjalmers commented 6 years ago

Sorry I haven’t posted an example yet, I’ve been really busy and I’m afraid this will have to wait as I’m away on a holiday now. You should however be able to get the index from the $$gtRowId, it’s a unique id for every row and the number in the beginning is the row index so just use something like this to get it.

row.$$gtRowId.split('_')[0]
vaydich commented 6 years ago

Thanks. I got it. But one point remains unresolved for me - server side paging. Which id will have the element number 44 (i think it will not be 44_nh9t4jk5zto for example)?

hjalmers commented 6 years ago

With 4.15.0 there's a new property called $$gtInitialRowIndex on each row which holds the original order of the row, which you might find useful @vaydich. As for server side pagination, please check #244 and #245 as they're related.