same mRender function for multiple columns

same mRender function for multiple columns

jogloranjogloran Posts: 1Questions: 0Answers: 0
edited October 2012 in DataTables 1.9
I'm using mRender to provide a rendering function for two columns in a DataTable. However, I can't use the same aoColumnDefs entry for both columns, because they access different columns of the data source, and mData only allows me to specify one column index.

Do I really need to repeat the mRender declaration for each column, even when they use the same renderer function, like so?
[code]
$('#vis').dataTable({
'aoColumnDefs': [
{ 'mRender': rendererFunction, 'mData': 3, 'aTargets': [ 3 ] },
{ 'mRender': rendererFunction, 'mData': 4, 'aTargets': [ 4 ] },
]});
[/code]

Replies

  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin
    No you can do this:

    [code]
    $('#vis').dataTable({
    'aoColumnDefs': [
    { 'mRender': rendererFunction, 'aTargets': [ 3, 4 ] },
    { 'mData': 3, 'aTargets': [ 3 ] },
    { 'mData': 4, 'aTargets': [ 4 ] }
    ]});
    [/code]

    mData is different so of course that needs to be individually assigned (although in this case, you are just setting it to what DataTables would do anyway - so it shouldn't be needed).

    Allan
  • josdemosselmanjosdemosselman Posts: 6Questions: 0Answers: 0
    Hi, i'm having sort of the same question...
    I'm using mrender function to display, on the id-field, an image containing a link.
    In the same table, i have to merge column 5 and 6, and display an image as well.
    Below the function I use for the first column.
    How do I do that?

    Thanks in advance!

    [code]
    "aoColumnDefs": [ {
    "aTargets": [ 0 ],
    "mRender": function ( data, type, full ) {
    return '';
    }
    }
    ],
    [/code]
  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin
    You need to specify an `mData` option. If that doesn't work, please link to a test case.

    Allan
  • josdemosselmanjosdemosselman Posts: 6Questions: 0Answers: 0
    Hi alan, thanks for the support, but i'm sorry to say, but i'm still stuck... :-s
    Testcase is http://www.thevinyltouch.be/dev/index.php?page=Webshop

    On the IDfield, there has to be an image (as defined in the code) but how do I specify de mData option?
    I'm kinda new with datatables, i'm sorry to bother you with this...
  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin
    Use:

    [code]
    mData: 0
    [/code]

    To get the data from the first column.

    Allan
  • josdemosselmanjosdemosselman Posts: 6Questions: 0Answers: 0
    hi alan,
    i fixed the problem, thanks for the support! datatable is up and running :)
  • mephimephi Posts: 1Questions: 0Answers: 0
    edited April 2013
    Hey Alan,

    I have an "actions" column where I need to add two links, Edit and Delete.
    The links can't be something like edit.php?id=mData and delete.php?id=mData so I have to pass them separately as hidden columns.
    How can I use two hidden columns mData (let's say mData: 0, and mData:1, these two being editlink and deletelink) into Actions column?

    Also, for the delete link, I need to add a confirmation alert where I have to pass the "title" column value (mData: 2) ... how can I get that?

    Thanks for the help!
  • harishraoharishrao Posts: 13Questions: 6Answers: 0
    edited May 2014
            $(document).ready(function () {
    
                var oTable = $('#myDataTable').dataTable({
                    "bProcessing": true,
                    "bSearchable": true,
                    "sAjaxSource": '@Url.Action("TaskAssigned", "Admin")',
                    "bVisible": true,
                    "bDeferRender": true,
    

    "aoColumnDefs": [
    { "bSortable": false, "aTargets": [0] }
    ],

                    "aoColumns": [
                                        { "mData": null, align: 'Center', sWidth: '2%' },
                                        { "mData": "TaskId", align: 'Center', "bVisible": false, "bSearchable": true },
                                         { "mData": null, "bSearchable": true,
                                             mRender: function (data, type, row) { return row.ImagePath + ' ' + row.UserName; }
    

    });
    });

    Here I m Combining Two column into one Column Like userName & His Image.......... Image will be storing in folder............. Path i m Getting from DB .................Works Fine.....

  • techaddict009techaddict009 Posts: 7Questions: 1Answers: 0

    Hasnt mRender deprecated now? How to solve similar problem with the latest version of datatables?

  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin

    No fnRender was removed. The mRender option still works, although in the new notation it is called render (i.e. columns.render).

    You might find this conversion guide useful.

    Allan

This discussion has been closed.