Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Igx grid sum of selected rows
posted

Hi Team,

I'm using igniteui-angular package with version 8.0.3 and using in angular project with angular version 6.

In igx-grid, I want the sum of a column for the selected rows only( rows with check-boxes checked). Please help/guide me to achieve the same.

Thanks & Regards,

Akshay

Parents
No Data
Reply
  • 40
    Offline posted

    Hello Akshay,

     

    Thank you for your inquiry!

    In order to get the desired result, according to the docs, it’s recommended that you provide a primary key. That can happen by setting a primaryKey attribute on your igx-grid element. After that, you may wish to listen for an update in the state of the grid’s checkboxes. That would happen by setting an onRowSelectionChange event listener on your grid. It receives an $event property, which has two parameters that are concerning us in the particular case: oldSelection and newSelection. OldSelection are the selected elements prior the event and newSelection is what’s checked after the event was fired. We’d like to use newSelection.

    In the newSelection array we got the primary keys of the rows we’ve selected. Now we may wish to obtain the data in each respective row. That could be done with a call to the getRowByKey method on the grid. As an argument to that call one has to pass the primary key from the newSelection array. As a result, an instance of IgxGridRowComponent would be returned, which keeps all the data into the selected row besides all the other meta data. One could easily obtain the information from the desired col via the rowData method.

    I’ve created a sample that’s forked from the igx-grid docs in order for you to have a better understanding on my explanations. You can find it here: stackblitz.com/.../angular-ko2rru-d3ekbe

     

    Best regards,

    Petko Bozhinov

Children