Columns.Render - Accessing data for more than 1 column in the render function

Columns.Render - Accessing data for more than 1 column in the render function

tomzntomzn Posts: 29Questions: 9Answers: 2

Hi all,

I am using datatables with server side rendering and my render function is as follows for a column in my table :

             {
                    "data": "Errors",
                    "width": "5%",
                    "orderable": false,
                    "render":
                        function (data, type, row) {                             
                            var myUrl = '@Url.Action("Foo", "Bar")/' + data;
                            return '<a href=\"' + myUrl + '\">'+data+'</a>';

                        }
                }

What I need to do is display the value for the data (which is the errors colum) in my link but pass the value of another column (id) as the parameter when the url is clicked. So for the line var myUrl = '@Url.Action("Foo", "Bar")/' + data; I would like to pass the value of the 'Id' column as data. Is there any way to do this ?

Thanks

This question has accepted answers - jump to:

Answers

  • tomzntomzn Posts: 29Questions: 9Answers: 2
    Answer ✓

    I managed to solve this by doing the following :

     {
                        "data": "Id",
                        "width": "5%",
                        "orderable": false,
                        "render":
                            function (data, type, row) {                             
                                var myUrl = '@Url.Action("Errors", "eBillingDashBoard")/' + data;
                                return '<a href=\"' + myUrl + '\">'+row.Errors+'</a>';
    
                            }
                    }
    

    I'm passing Id as before whilst using the row.Errors parameter of the row object to display the literal value of errors.

    Thanks to all who read the post and attempted to help.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You are correct - as the columns.render documentation notes, the third parameter passed into the rendering function contains the data for the whole row and you can access it form there.

    Allan

  • guillochonguillochon Posts: 56Questions: 19Answers: 0

    But the third parameter only contains the data pre-rendering, correct? What if I want to use the output for the render function for another column?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Correct. There is no option to get the rendered data from another column in a rendering function. You'd effectively need to rerender it again.

    Allan

This discussion has been closed.