Author Topic: Change data to the cell via rowInit, lost changes after applying filter  (Read 313 times)

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
We are updating cell value based on the condition and it's working fine with rowInit method.

The changes are lost after we filter on the grid. Please review the code below & attached screenshots and advise to fix this.

1_9112022.png: Data loaded with updated text in the status column based on rowInit method.
2_9112022.png: Lost changes after applying the filter. Need your help to fix this.

Code: [Select]
rowInit: function (ui)
                {                   
                    if (ui.rowData.Exchange == "NSECM")
                    {
                        ui.rowData.Exchange = "NSE";
                    }

                    var lsOrderStatus = "None";
                    switch (ui.rowData.OrderStatus)
                    {
                        case 48:
                            lsOrderStatus = "None";
                            break;
                        case 49:
                            lsOrderStatus = "Submitted";
                            break;
                        case 50:
                            lsOrderStatus = "MPending";
                            break;
                        case 51:
                            lsOrderStatus = "EPending";
                            break;
                        case 52:
                            lsOrderStatus = "Freezed";
                            break;
                        case 53:
                            lsOrderStatus = "MRejected";
                            break;
                        case 54:
                            lsOrderStatus = "ERejected";
                            break;
                        case 55:
                            lsOrderStatus = "Cancelled";
                            break;
                        case 56:
                            lsOrderStatus = "ECancelled";
                            break;
                        case 57:
                            lsOrderStatus = "Executed";
                            break;
                        case 65:
                            lsOrderStatus = "ESOrder";
                            break;
                        case 66:
                            lsOrderStatus = "ESTrade";
                            break;
                        case 83:
                            lsOrderStatus = "SLPending";
                            break;
                    }
                    ui.rowData.OrderStatus = lsOrderStatus;

                    if (ui.rowData.OrderPrice > 1000)
                    {
                        return {
                            style: { "background": "yellow" } //can also return attr (for attributes) and cls (for css classes) properties.
                        };
                    }
                    else if (ui.rowData.OrderPrice > 500)
                    {
                        return {
                            style: { "background": "aqua" } //can also return attr (for attributes) and cls (for css classes) properties.
                        };
                    }
                },
                cellSave: function (evt, ui) {
                    this.refreshRow({ rowIndx: ui.rowIndx });
                },




paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Change data to the cell via rowInit, lost changes after applying filter
« Reply #1 on: November 09, 2022, 09:15:07 pm »
Your logic is faulty considering the rowInit is called multiple times in the lifecycle of grid. ui.rowData.OrderStatus is set to "None" during 2nd call.

Also rowInit is not to be used for making any persistent changes in data.

Please use js formulas or rowTemplate to make any conditional changes. ui.rowData.OrderStatus value shouldn't be dependent upon itself.