getError not working after deleting rows

Posted by: ken_perregaux on 20 June 2018, 1:12 am EST

  • Posted 20 June 2018, 1:12 am EST

    Background. We are 2 types of validation. For cell validation in a row we are using 'getError' and it seems to work great (except it gets call a ton and for large tables may be a problem). Then once a row is complete, using 'onRowEditEnded', we call a service to either save the row in a database or return an error. We use 'itemFormatter' to show error if there is one. We also call our service to add a new row (it returns a new object that is added to the CollectionView) and delete row(s) (it returns a list of the remaining objects and I repopulate the CollectionView and call refresh on the CollectionView and the grid.

    However, if I have an invalid row from 'getError' the formatting does not occur after deleting other rows. I can see the 'getError' getting called for the first property for that row and an error message is returned but no formatting is being done.

    Any help would be greatly appreciated.
  • Replied 20 June 2018, 11:03 pm EST

    Hi Ken,
    As we understand, you have getError method and itemFormatter to show an error for FlexGrid. But on deleting the row content, the getError do not work correctly.

    If yes, we are sorry we are unable to replicate the issue at our end.
    Please refer to the following demo sample for the same:
    https://stackblitz.com/edit/js-5lcry2?file=index.js

    Please modify this to replicate the issue at our end or you may share demo sample depicting your issue.
    ~Manish
  • Replied 21 June 2018, 12:48 am EST

    The problem is if I use the CollectionView's remove function things work great. But if I do what we are doing (making a call to a server to remove the rows from the DB) and then return the remaining rows and repopulate the CollectionView and try to call either its refresh, the tables refresh or invalidate the getError does not function properly. I will attach my HTML and TS file example.

  • Replied 21 June 2018, 12:50 am EST

    example.zip
  • Replied 21 June 2018, 7:54 am EST

    So sorry, I found my problem, when I reinitialized the CollectionView (with a new) the getError handler went away.
  • Replied 21 June 2018, 10:59 pm EST

    Hi,
    We are glad to know that you were able to solve your problem.

    P.S. If you have a requirement to repopulate the collectionView then please use collectionView.sourceCollection property of CollectionView.
    Please refer to following code snippet:
    var newData=data_to_repopulate;
    grid.collectionView.sourceCollection=newData();
    grid.invalidate();

    If you need any further assistance please let us know.

    ~Manish
  • Replied 25 November 2020, 9:34 pm EST

    Dear Manish,

    I'm facing a similar issue. I have a row where multiple cells have an error. I fix the error of one cell and send the changes of the row to the server. The server sends the updated row back as the answer. In the data of the row contains the error of the cells where I didn't fix the error. But in the grid, the errors are not visible.

    What I do when I get the response from the server is to change the data in the grid and commit it. Roughly like this:

    let list = this.flexdata.collectionView.sourceCollection;
    let oldItem = lits[indexOfOldItem]
    this.data.editItem(oldItem);
    oldItem = _.merge(oldItem, newItem);
    delete oldItem.dirty;
    this.data.commitEdit();


    Is there a way to fix this?

    Best regards
    Moritz
  • Replied 26 November 2020, 8:15 pm EST

    Hi Moritz,

    Please make sure that you are not assigning the itemsSource of the FlexGrid to a new CollectionView or an array. It may be possible that the internal collection view of the grid is updated with a new CollectionView, which does not contain the implementation of getError.

    If this does not resolve your issue, then can you please modify the sample below so that it replicates the issue. It would be easier for us to investigate:

    https://stackblitz.com/edit/angular-7bwofg

    Regards,
    Ashwin
  • Replied 29 November 2020, 11:24 pm EST

    Dear Ashwin,

    thank you for your response. Everytime the getError method is called, I print out itemsSource to see if maybe there is a new instance of the CollectionView is used that does not cointain the implementation of getError. But this is not the case in my code.

    It would be pretty hard for me to modify the sample so that it replicates my issue as I would ne to speak to a server :(

    One thing that I observed is, that for some rows/cells I can see the error, when I hover over the cell or the row header. Maybe you have an idea why the tooltip pops up, but the cell itself isn't highlighted?

    Hover over last cell:


    Hover over row header:


    Best regards
    Moritz
  • Replied 30 November 2020, 10:53 pm EST

    Hello Moritz,

    Can you please try to call the invalidate method of FlexGrid after updating the data in the CollectionView?
    this.data.commitEdit();
    this.flexdata.invalidate();

    It may be possible that the FlexGrid is not refreshed properly after the data is updated.

    Also, regarding the modification of the sample, you can modify the sample without a server. We are only interested in the client-side of your application. You can even create a dummy method that acts as a server, to replicate your issue.

    Let us know if the invalidate method works.

    ~regards
  • Replied 7 January 2021, 11:13 pm EST

    Dear Ashwin,

    sorry for the late response.

    Calling this.flexdata.invalidate() doesn't fix the behaviour.

    Just to recap what I do. I create a new row which has two cells where an entry is required. But I leave these two cells empty. Both cells are highlighted as errors, which is fine.

    Now i add data to one of the cell and save the changes to the server. The server responds which the edited row. In the data of that one cell, the errorStatus is empty. But still both cells are highlighted as errors.

    This is my code for updating a row.


    if (updatedItems.length > 0) {
    let result = await this.drs.updateKatalogAttributeWerte(this.version.id, updatedItems);

    let list = this.flexdata.collectionView.sourceCollection;

    for (let item of result['result'].body) {
    let index = list.findIndex(entry => entry.id === item.prevId || entry.id === item.id);
    if (index > -1) {
    this.data.editItem(list[index]);
    list[index] = Utils.convertKatalogwert2Native([item], this.katalogAttributeMap)[0];
    delete list[index].dirty;
    this.data.commitEdit();
    this.flexdata.invalidate();
    }
    }
    }
    if (updatedItems.length > 0 || createdItems.length > 0) {
    this.flexdata.select(range.row, range.col);
    }


    THis is my getError Method

    getError(item: any, prop: string) {
    let bindingParts = prop.split('.');

    let result = [];

    if (bindingParts.length > 1 && item.attributWerte
    && item.attributWerte[bindingParts[1]]
    && item.attributWerte[bindingParts[1]].errorStatusSet
    && item.attributWerte[bindingParts[1]].errorStatusSet.length > 0) {
    result.push(item.attributWerte[bindingParts[1]].errorStatusSet);
    }

    return result.join();
    }
  • Replied 8 January 2021, 2:30 am EST

    Hi Ashwin,

    I finally understood how updating an existing entry in the grid works. The initial bug appear because I was using lodash merge function to copy values from the object coming from the server into the existing object. ErrorStatus was stored in an array. Merge function handles merging arrays in a different way then I needed so I started using lodash mergeWith. Now the initial bug disappeared and highlighting errors in the grid works like a charm.

    Thank you very much for the comments in your provided example. This made me understand the real problem in my code.

    Best regards
    Moritz
  • Replied 10 January 2021, 4:16 pm EST

    Hi Mortiz,

    I am glad that you were able to resolve your issue. Please let me know in case you run into any issues in the future.

    ~regards
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels