how to get column name from the table to use for href link
how to get column name from the table to use for href link
I am using the following code to make a link for a new page:-
columnDefs: [
{
targets: [2],
render: function ( data, type, row, meta ) {
if(type === 'display'){
data = '<a target="_blank" href="link.php?name=' + row[2] +'">' + data + ' </a>';
}
return data;
},
},
],
i need to get the column name instead of data.
regards
This question has an accepted answers - jump to answer
Answers
I'm not sure what you mean by the name. Where are you defining the name? Do you mean
columns.name
? If so, I don't see it in the above code.Allan
Hi Allan,
Thank you for your response, i am using the following dynamic code.
var data,
tableName= '#Dynamic',
columns,
str,
jqxhr = $.ajax('test.php')
.done(function () {
data = JSON.parse(jqxhr.responseText);
Thanks - however, I'm not actually clear on where the error is. Could you clarify where in the above code you are having a problem and what it is that you want it to do?
Thanks,
Allan
in line 36 above code it give me "undefined "
i want have the column name or row[number] both are the same error
Is the line with the error.
My guess is that you need to use
columns[1]
to get the data, since your data source appears to be arrays, not objects. Its difficult to say without a test case, but there is nocolumns.data
option, which suggests that it is an array data source.Allan
test number 1:-
this is the error message after using columns[2] :-
Notice: Undefined index: column "in line number"
Yes the data source is array correct
test number 2:
modify code using
columns.data
not working
With console.log you can see what columns is and what it contains. Just put this line
console.log('columns = ' + columns);
before your line where filling data with a hyperlink.I try the as following your code
targets: 1,
render: function ( data, type, row, meta ) {
if(type === 'display'){
console.log('columns = ' + columns);
data = '<a target="_blank" href="Dynamic_tweets_report.php?screen_name=' + screen_name +'&data_type=' + data_type +'&column=25' +'&description=' + row[0] +'">' + data + ' </a>';
}
return data;
},
},
No effect or any thing show in
You are initializing your
columns
variable:But I don't see where you are populating it with anything. Maybe you need to add something like this to your loop that builds the table headers:
columns.push(colObj.name);
And change your variable init to this:
Kevin
Kevin,
I am using a dynamic column creating when i get my query and send back to ajax, if you read the code it is a very good example created by datatable team it is work very good get the data. what i am try to do is a href link and try to send the data for my second page but not getting any data.
Still waiting to get and find a solution for my problem. any way thank you Kevin for trying.
Rather than us guessing about the full initialisation and data, please post a link to a test case showing the issue so we can help to debug the live running code.
Allan
Thank you allan he are the link :
http://jbmruby.com.cws17.my-hosting-panel.com/datatabledemo/Dynamic_Details_report.php
if you click on screen_name this is the correct result i want:-
http://jbmruby.com.cws17.my-hosting-panel.com/datatabledemo/Dynamic_tweets_report.php?screen_name=_HugMeDolan_&data_type=4&column=25&description=@HayesGrier
if you click on month of Oct.
http://jbmruby.com.cws17.my-hosting-panel.com/datatabledemo/Dynamic_tweets_report.php?screen_name=_HugMeDolan_&data_type=2&column=12&description=*************
I need to get the data value of description to be post link when you click on screen_name.
I post the code above, thanking that enough.
Please Gentlemen, HELP needed ?????????
Should be:
Your data object is an object not an array.
Allan
Thanks allan, the best tools with the best support.