Victor
Victor

Reputation: 17107

extjs conditionally render columns

lets say I have a gridpanel with 2 columns :Name and Salary, The dataIndex of the corresponding store has the same names

In extjs, a renderer function goes like this:

function(value, metaData, record, rowIndex, colIndex, store){}

Now, when I call a randerer, based on the name of the proeprty, if I wish to do different rendering, how do I go about it? e,g.

function(value, metaData, record, rowIndex, colIndex, store){
if (record.name == 'Salary'|| record.id == 'Salary')
{
//render logic
}
else if (record.name == 'Name'|| record.id == 'Name'){
  //different render logic
}
}

What is the correct syntax for this?

Upvotes: 1

Views: 4231

Answers (1)

Abdel Raoof Olakara
Abdel Raoof Olakara

Reputation: 19353

Well, syntactically that is correct. But the conditions in the if statement are not correct. The value variable holds the value that is being rendered, so if you need to check against that it should be fairly simple if condition.

In your case you are trying to render Salary or Name? The record variable holds the entire record. There is no record.name field. The record object holds the following fields:

  1. data -> Is an object with data. (Use should be using this)
  2. id -> Id of the record. This is specified by idProperty in your store
  3. json -> data in json format
  4. store -> Your store itself
  5. proto -> prototype

So, if you are doing any comparison and check you will need to use record.data.<property-name>.

In your case you have a single dataIndex for both name and salary, so the code will be:

function(value, metaData, record, rowIndex, colIndex, store) {

    if(record.data.property == Name) {
            //render logic for name
    }
    else if(record.data.property == Salary) {
            // render logic for salary
    }
}

And finally, this function will go into the renderer property of your column.

Upvotes: 1

Related Questions