Render column as a link

Render column as a link

arul27arul27 Posts: 4Questions: 1Answers: 0
edited July 2019 in Free community support

I am generating a datatable using dynamic columns. I need to render one of the columns as a link using the render property. Below error is thrown while trying to achieve it.
DataTables warning: table id=WorkLoadGrid - Requested unknown parameter '' for row 0, column 0

code snippet:
WorkLoadHeadings.Render = "function ( data, type, row, meta ) { return '<a href=' + data + '>Download</a>'; } ";

script:

$.each(result.WorkLoadHeadings, function (i, value) {
                        column.push({ "data": value.ColumnName, "title": value.ColumnDescription, "name": value.ColumnName, "Width": 4, "render": value.Render });
                    });
                    $('#WorkLoadGrid').DataTable({
                        bLengthChange: false,
                        bPaginate: false,
                        bInfo: false,
                        scrollY: "370px",
                        scrollX: true,
                        filter: false,
                        paging: false,
                        data: result.GridDataList,
                        columns: column,
                    });

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @Arul27 ,

    Take a look at the fourth example of columns.render, it's showing how to generate a link,

    Cheers,

    Colin

  • arul27arul27 Posts: 4Questions: 1Answers: 0

    Hi Colin,

    Thanks for the response. I am also following the code snippet given in that example but am getting the error below.

    DataTables warning: table id=WorkLoadGrid - Requested unknown parameter '' for row 0, column 0

    Thanks,
    Arul

  • kthorngrenkthorngren Posts: 20,254Questions: 26Answers: 4,761

    You are using data: result.GridDataList,. What does data: result.GridDataList contain? Did you follow the troubleshooting steps provided in the alert error link?
    https://datatables.net/manual/tech-notes/4

    Kevin

  • arul27arul27 Posts: 4Questions: 1Answers: 0

    result.GridDataList is the array collection which will have the required data for the table.

  • kthorngrenkthorngren Posts: 20,254Questions: 26Answers: 4,761

    Can you post an example of the data in result.GridDataList?

    And does the structure of result.GridDataList match the structure you are building for the columns? Maybe you can post and example of the resulting column variable.

    Kevin

  • arul27arul27 Posts: 4Questions: 1Answers: 0

    Below is the values assigned in result,GridDataList . Trying to render the values in column ContractLastFirstName as a link button.

This discussion has been closed.