mRender function get data from another column

mRender function get data from another column

fearednerdfearednerd Posts: 44Questions: 0Answers: 0
edited September 2013 in General
I am trying to create a hyperlink with mRender. Unfortunately I need the name and the id which are in 2 different fields in the json.

Basically the json is like
[code]
{
"aaData": [
{
"id": 1,
"model": "ccc.changerequest",
"fields": {
"name": "aa",
"post_time": "2013-08-21 17:12:37",
"risk_1": "a",
"delivery_manager": "pyi1",
"staging_datetime": null,
"author": 2
}
},
]}
[/code]
I was wondering if there was anyway so I could get mRender to get both the Id and field.name to create the link.

i tried setting the mdata for a column to be field.name and another to be the id and use mrender function to return data + " " + row[id row] but with no success.

Any help/advice is greatly appreciated.
Willing to post any more information if it will help.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited September 2013
    The later one :-)

    [code]
    mData: 'id',
    mRender: function ( data, type, row ) {
    return row.field.name +' '+ row.id;
    }
    [/code]

    Allan
  • fearednerdfearednerd Posts: 44Questions: 0Answers: 0
    Thanks for the quick reply like always. Unfortunately I'm getting that fields.name is not defined or id is not defined.

    [code]
    "aoColumns": [
    {"mData": "fields.name"},
    {"mData": "id"}
    ],
    "aoColumnDefs": [
    {
    "mData":"fields.name",
    "aTargets":[0],
    },
    {
    "mData":"id",
    "mRender": function(data, type, full) {
    return fields.name + " " + id;
    },
    "aTargets":[1]
    }
    ]
    [/code]

    This is what I have.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited September 2013
    Doh! I've just corrected my comment. Should have been `full.fields.name` etc.

    Allan
  • fearednerdfearednerd Posts: 44Questions: 0Answers: 0
    i got the error id was undefined but I realized it's basically the data parameter.
    I changed it to return full.fields.name+ " " + data;
    Everything works now. Thanks once again.
This discussion has been closed.