Rendering data from ajax call

Rendering data from ajax call

annafwannafw Posts: 16Questions: 4Answers: 0

Hi,

My company uses Datatables on different sites in our web-app. So, one of them has a column containing a link, but we can't click on it. We tried to use columnDefs with the render option, but it seems like this one is never called. We did similar things before, but the ajax calls were slightly different. I wonder if this could be the reason why columnDefs & render don't work?

Unfortunately I can't create a working fiddle. :neutral:

addDataTable({
            table: 'model-table',
            elementName: 'Modell',
            ajax : {
                url : '/modeldata',
                data : function( request ){
                    $('#adparam-form :input:not([type=hidden])').each(function(){
                        var it = $(this);
                        request[it.prop('name')]=it.val();
                    });
                    request.selection_block = $('#adparam-selection').val();
                }
             },
            clientSide: true,
            fileName: 'ModelleFür*',
            columnDefs: [{
                    targets: 2,
                    render: function(data, row, meta) {
                        return '<a href="' + data + '">' + data + '</a>';
                    }
                }]
        });

This is our table. Do you have any ideas what could be the issue?

Regards

Anna

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    column containing a link, but we can't click on it.

    Looks like it should work.

    Do you get the indication its a link when you hover over it?

    Do you get errors in the browse's console when you click on it?

    Right click on the link and inspect it to see the HTML being rendered.

    Kevin

  • annafwannafw Posts: 16Questions: 4Answers: 0

    Hi Kevin!

    Yeah, we thought that too. It isn't rendered as a link. The HTML is just

    <td>www.xyz.com</td>
    

    instead of

    <td><a href="www.xyz.com">wwww.xyz.com</a></td>
    

    We don't get any errors.

    Anna

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    This example shows your columnDefs option works as expected:
    http://live.datatables.net/nuyizule/1/edit

    Looks like you might be using a framework that supports Datatables as there are options defined that aren't Datatables options. Maybe there is a default Datatables config setup that is overwriting the columnDefs. There is noting else obvious from the code snippet above.

    Can you link to your page so we can take a look?

    Kevin

  • annafwannafw Posts: 16Questions: 4Answers: 0

    We created our own default Datatables config setup which we overwrite if necessary. I checked it and removed the specified columnsDef option there, but it had no impact.

    I'm afraid our page is just reachable from our local network, therefore I can't link it here.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Maybe you have columns.render in your columns option. Looks like that will override the columnDefs. See this updated example:
    http://live.datatables.net/lafepixi/1/edit

    Also note the parameter names you have render: function(data, row, meta) are not correct. The order should be render: function(data, type, row, meta).

    Kevin

  • annafwannafw Posts: 16Questions: 4Answers: 0

    We don't use the columns.render option in this table (just to be sure I removed it from our default too). I tried to use them instead of columns.def render, but the result is the same.

    Thanks for the hint concerning the parameters!

  • annafwannafw Posts: 16Questions: 4Answers: 0

    Update: You were right, Kevin. Our default table had bugs concerning columnDefs option, which caused the issue. Thanks for your help!

This discussion has been closed.