Edit Tables - Column Default Contents - link based on field Value
Edit Tables - Column Default Contents - link based on field Value
Hi Everyone
I've created a edit table with a button in the last column (a hef control) which is linked to a page called /system/maintainStandardAnswers.php what I need to do is pass the page the parameter id with the value held in the table tblQuestionBankQuestions and the field ID - tblQuestionBankQuestions.id
var table = $('#example').DataTable( {
dom: "Bfrtip",
ajax: "../server_side/scripts/ET_questionsBank.php",
iDisplayLength: 25,
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{ data: "tblQuestionBankQuestions.question" } ,
{ data: "tblquestionTypes.questionType", editField: 'tblQuestionBankQuestions.questionType' } ,
{ data: "tblQuestionBankQuestions.projectField" } ,
{ data: null,
className: "centre",
// defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
defaultContent: '<a href="/system/maintainStandardAnswers.php"><input id="maintainAnswers" name="maintainAnswers" value="Maint. Answers" class="btn btn-primary" readonly /></a>'
],
order: [ 1, 'asc' ],
Is there a way of adding this to the a href?
e.g.
defaultContent: '<a href="/system/maintainStandardAnswers.php?ID=' + tblQuestionBankQuestions.id +'"><input id="maintainAnswers" name="maintainAnswers" value="Maint. Answers" class="btn btn-primary" readonly /></a>'
Thank you in advance of anyhelp you can give.
This question has an accepted answers - jump to answer
Answers
Use column.render instead of defaultContent.
Thank you Tangerine, but I'm really new to this and I haven't got a clue what you mean... Is there an example you can point me to?
Thank you Tangerine.... I found a page that helped me. all I needed to do was change the code of the last column from null to use the field tblQuestionBankQuestions.id then change the 1 line from :
defaultContent: '<a href="/system/maintainStandardAnswers.php"><input id="maintainAnswers" name="maintainAnswers" value="Maint. Answers" class="btn btn-primary" readonly /></a>'
to
render: function (data, type, full, meta) {
return type = '<a href="/system/maintainStandardAnswers.php?ID='+data+'"><input id="showListOffices" name="showListOffices" value="Maint. Answers" class="btn btn-primary" readonly /></a>'