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 underlying value change issue for percentage field
posted

I have a requirement inside IGX editable grid. The column data need to display as multiply with 100. In grid edit mode also we need to display the input value multiply with 100. But after edit the value need to convert to divided by 100. And the view will be same as edited value.

I have used a pipe to display the value multiply with 100 and in edit mode I have changed the input value using focus event. But after every edit the value is always multiplied with 100. So, it's displaying the wrong value after each edit. So how to prevent this particular issue?

Thanks & Regards,

Santu

Parents
  • 400
    Offline posted

    Hello Santu,

    I have been looking into your question and to achieve your requirements what I could suggest is to handle the cellEditEnter and cellEditExit events of the igx-grid component and multiply or divide the edited value and the displayed value of the cell of the given data column.

    <igx-grid
          #grid
          [data]="data"
          [primaryKey]="'ProductID'"
          width="100%"
          height="650px"
          (cellEditEnter)="editStart($event)"
          (cellEditExit)="editExit($event)"
        ></igx-grid>

    First, you will handle the cellEditEnter event and when the event fires, you will check if the cell being edited is from the given column for the multiplied values, if it is, you will take that cell with the getCellByColumn method, passing the index of the row and the field of the column, and you will multiply the editing value by 100 so that it is displayed in the correct form.

    public editStart(event){
          if(event.cellID.columnID === 2){
            Math.round(this.grid.getCellByColumn(event.cellID.rowIndex,"Percentage").editValue *= 100)
          }
     }

    After that, the cellEditExit event will be handled and when it fires after editing a cell or simply leaving the cell without editing, you will take the given cell again with getCellByColumn method and the edited value and the displayed value will be divided by 100 to return to the initial state and display as required.

    public editExit(event){
          if(event.cellID.columnID === 2){
            Math.round(this.grid.getCellByColumn(event.cellID.rowIndex,"Percentage").editValue /= 100)
            Math.round(this.grid.getCellByColumn(event.cellID.rowIndex,"Percentage").value /= 100)
          }
        }

    The described scenarios could be observed here where initially, the values have a decimal point and are displayed as a multiple by 100 in the 'Percentage' column:

     

    In addition, I have prepared small sample illustrating this behavior which could be found here. Please test it on your side and let me know how it behaves.

    If you require any further assistance on the matter, please let me know.

    Regards,

    Georgi Anastasov

    Entry Level Software Developer

    Infragistics

Reply Children
No Data