Access Jquery "data" parameter of the row inside render function

Access Jquery "data" parameter of the row inside render function

sergedasergeda Posts: 42Questions: 16Answers: 0

I'm trying to get Jquery "data" parameter of the row inside render function for the column. Is this possible?

Replies

  • kthorngrenkthorngren Posts: 21,449Questions: 26Answers: 4,975

    The columns.render function parameters are function render( data, type, row, meta ). As mentioned in the doc the data parameter is the data for the cell.

    I'm not sure I understand what you mean by Jquery "data" parameter. Can you provide more details of what you want to do?

    Kevin

  • segfaulcoredumpsegfaulcoredump Posts: 5Questions: 0Answers: 1

    I have the following snippit in my code under the 'columns' section:

    { "data": "full_name", "render":  
        function (data, type, row) {
            if (type == "sort" || type === 'type') return data;
            if (type == "filter" || type === 'type') return row.full_name_filter;
            if (row.award_winner == "yes") 
                     return '<i class="fa fa-trophy" aria-hidden="true"></i> ' + row.full_name;
            else return row.full_name;
            }
                     
        },
    

    You can see the entire thing in action here: http://www.pikespeakmarathon.org/results/ppa/2017/

    Note that all of the data for the table is sourced by a javascript / json data object. It is not dom driven.

    For the render function, we have three parameters: data, type, row. (I have no idea what 'meta' is for and just ignore it.) The first parameter, 'data' is the data entry for the cell (the "full_name" attribute), 'type' is the type ("sort", "filter," etc), and 'row' is the data structure for the entire row.

    There are a few things going on here:
    If I need to return data for a sort, I just return the cell value
    If I need to return data for a filter, I return the full_name_filter data (this contains both us-ascii and utf-8 values for ease in searching)
    If anything else (like the display) I want to display the fa-trophy icon in front of participants who are award winners. I have a "award_winner" attribute for the row that tracks this. So if that attribute is set to yes, I return the icon with the full_name attribute. Otherwise I just return the full_name attribute.

    I hope this helps.

    --john

  • sergedasergeda Posts: 42Questions: 16Answers: 0

    To clarify my question.
    I have rows in the table specified like this:
    <tr data-recordType="mytype"><td>id</td><td>other value</td></tr>

    and then inside render function for column with id I want to get recordType for current row. Is this possible?

  • kthorngrenkthorngren Posts: 21,449Questions: 26Answers: 4,975

    You can access it using createdRow. For example:

        createdRow: function( row, data, dataIndex ) {
            console.log($(row).attr("data-recordType"));
        }
    

    Kevin

  • sergedasergeda Posts: 42Questions: 16Answers: 0

    Thanks Kevin

This discussion has been closed.