2
votes

I have a a gridpanel that has the following fields:

Name ID Address Home_Phone Cell

Some records that return to the store may not have any data for some of these fields, rather then display an empty column for that record in the grid I would like to show a default value of N/A.

So I would have

Name     ID   Address      Home_Phone    Cell
Shaun    2    My Address     N/A          N/A

Rather then:

Name     ID   Address      Home_Phone    Cell
Shaun    2    My Address   

I know of two ways to do this:

  1. In the back end if the field doesn't exists return a "N/A" for that column in the JSON.
  2. Create a template with a method that check if the record doesn't contain the value return "N/A".

My question is, is there an easier way to tell the grid column if no value is found in the record display the default N/A?

1

1 Answers

5
votes

You can add a renderer for your columns. You either add a renderer for each column or you can define your own column if you have more columns with this behaviour.

//add this for each column config (works for null values and empty strings)

{
    renderer: function(value){
        if (Ext.isEmpty(value)) {
            return 'N\\A';
        }
        return value;
    }
}

or add the renderer to a component that extends the column and use that throughout the application. It's easier to do this on the front end rather then modifying the backend and sent extra unnecessary data like 'N\A'.

Hope It helps.