Rendering data from ajax call
Rendering data from ajax call
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.
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
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
Hi Kevin!
Yeah, we thought that too. It isn't rendered as a link. The HTML is just
instead of
We don't get any errors.
Anna
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
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.
Maybe you have
columns.render
in yourcolumns
option. Looks like that will override thecolumnDefs
. 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 berender: function(data, type, row, meta)
.Kevin
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!
Update: You were right, Kevin. Our default table had bugs concerning columnDefs option, which caused the issue. Thanks for your help!