Find row by value and delete that row in FlexGrid

Posted by: joachim-feldt on 14 September 2017, 11:50 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 11:50 am EST

    Hello,

    I want to delete a row in a FlexGrid, Angular 2 version.

    I manage to delete the selected row, but that is not what I want. I want to delete another row and find that row by a value.

    I grid is bound to an array called “this.myOrders”, which is a list of orders.

    Then I search for a specific item by doing this:

    var order = this.myOrders.find(o => o.orderId == orderId);

    Then I would like to find that row in the grid containing this order and remove that row.

    I tried this: this.ordersFlexGrid.rows.remove(order);

    Bu that does not work.

    How can I do this?

    Thanks in advance!

    Regards,

    Joachim

  • Posted 14 September 2017, 11:50 am EST

    Hello Joachim,

    You need to pass rows reference to delete row from FlexGrid. Since you are passing dataItem of row, so remove method does not find row to remove. Please try following code snippet for deleting row from FlexGrid:

    
    deleteRow(){
        let c = this.flex.rows.find(o=>o.dataItem.orderId == orderId);
        this.flex.rows.remove(c);
    }
    

    Just for your information, row deleted from FlexGrid in this way, is deleted only from FlexGrid not from itemsSource.

    Hope this helps you.

    Thanks,

    Manish Kumar Gupta

  • Posted 14 September 2017, 11:50 am EST

    Hello,

    Thanks for your response.

    Yes, I do understand that the datasource is not updated. I do that in another function. If this is not the best way to do this, please let me know.

    The code works and the row gets deleted, however:

    I get a compilation error when running the code saying that “Property ‘find’ does not exist on type ‘RowCollection’”.

    Any idea how that can be resolved?

    Regards,

    Joachim

  • Posted 14 September 2017, 11:50 am EST

    Hello,

    It depends on the requirement that how you want to get items deleted in the application.

    Hence can’t comment much about it.

    Regarding the compilation error, it is because ‘find’ method is not defined in RowCollection which this.flex.rows return, so you need to check manually using for loop. Please use the following code snippet for avoiding compilation error:

    
    deleteRow() {
            let order = 5,
                c = {};    ;
            for (var j = 0; j< this.flex.rows.length - 1; j++) {
                if (this.flex.rows[j].dataItem.id == order) {
                     c = this.flex.rows[j];
                    break;
                }
            }
            this.flex.rows.remove(c);
        }
    

    Thanks,

    Manish Kumar Gupta

  • Posted 14 September 2017, 11:50 am EST

    Hello,

    Thanks a lot!

    Works great now.

    Regards,

    Joachim

  • Posted 31 May 2018, 5:48 pm EST

    i have object but my jobTolerance_ID is undefined . because i am creating a new record to save in database that is handled in DB.

    But i can delete empty records with out getting this error

Need extra support?

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

Learn More

Forum Channels