Edit Tables - Column Default Contents - link based on field Value

Edit Tables - Column Default Contents - link based on field Value

ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

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 :neutral:

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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    Use column.render instead of defaultContent.

  • ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

    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?

  • ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

    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>'

This discussion has been closed.