Author Topic: Format specific cell/row  (Read 2361 times)

joaosales

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 20
    • View Profile
Format specific cell/row
« on: January 30, 2018, 01:44:07 pm »
Hi,
How can I format a specific cell or an entire row? I've been able to change the format of a column, during the event of changing a value of a cell, but i haven't been able to apply the same thing for an entire row.
Right now i have a  column where you choose a currency in a dropdown list, and i would like to apply that currency symbol to the values in the row.


Thanks,

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6296
    • View Profile
Re: Format specific cell/row
« Reply #1 on: January 30, 2018, 04:09:15 pm »
Individual cells / cells in a row can be formatted with pq_format.

Code: [Select]
var json_data = [
        {
            "rank": 1, "company": "Exxon Mobil","revenues": 10,
            pq_format:{revenues:'%##.000', rank:'*##.0'}
        },
        {
            "rank": 2,"company": "Wal-Mart Stores","revenues": 11, 
            pq_format:{revenues:'@##.0000'}
        }
    ];

https://plnkr.co/edit/eIMkP9JTDJiSgN8cJnXv?p=preview

joaosales

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Format specific cell/row
« Reply #2 on: January 30, 2018, 07:43:59 pm »
For some items I already have the format symbol when build the grid, but for others I'll only get it after setting the the value at the currency cell of the row.
For now I tried setting at the postRender of the currency dropDown column, but it isnt changing the format, can you help me finding what's wrong or it doesn't work at the postRender?

Code: [Select]
postRender: function(ui){
                        let dataColumns = {};
                        let currencySymbol =getCurrency(ui.rowData.currency);
                        for(var colIdx in ui.rowData){
                            dataColumns[colIdx] = currencySymbol+"##.###,00";
                        }
                        ui.rowData.pq_format = dataColumns;
                }

Thanks,

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6296
    • View Profile
Re: Format specific cell/row
« Reply #3 on: January 31, 2018, 11:16:05 am »
postRender is called after rendering of the view, hence it's a wrong place to change/set format.

Format for the row should be set in the appropriate event, like in your case you want to set it when you set the currency cell of the row.

It should be set in a change event.
« Last Edit: January 31, 2018, 11:17:40 am by paramquery »