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
215
Persisting changeable state while keeping underlying column definitions
posted

It is listed as a limitation that the columns state doesn't allow functions and so to handle those in the initColumns but I have several templates for the column content so that doesn't seem very practical. Additionally if you store the entire column state then as far as I can tell if I add new columns in future any users with state stored won't pick up those new columns. So rather than restore the entire state of columns I just want to apply the things the user can actual change - visibility, pinning and order. Is there a way to get the existing columns definition to merge with the state first or to apply those parts programatically? I can see you can set pinning through api functions so I could read the state and call functions myself but I can't see how to hide or move columns through api. Is there anyway to achieve this?

Parents Reply
  • 215
    Offline posted in reply to Hristo Anastasov

    The problem is the limitation already mentioned:

    Limitations

    getState method uses JSON.stringify() method to convert the original objects to a JSON string. However, this does not support Functions, thats why the [IgxGridState] directive will ignore the columns formatter, filters, summaries, sortStrategy, cellClasses and cellStyles properties. It is up to the developer to keep track and restore those on application level. It is recommended to set these in the onColumnInit event:

    I already have all the logic for columns in the html. So I don't want to have to rewrite all that into a onColumnInit event instead. So that is why I was trying to reinstate the things the user can change only so that I don't lose all that other information when restoring the state

    e.g for one of my columns I have 

    <igx-column [filterable]="false" field="personId" header=" ">
                <ng-template igxCell let-cell="cell">
                    <mat-icon *ngIf="showEdit(cell.rowData)" (click)="editPerson(cell.value)">edit</mat-icon>
                </ng-template>
            </igx-column>
    If I restore the column state then it loses this template. 
Children