Display buttons in columns at the end of a row depending on another value in that row.
Display buttons in columns at the end of a row depending on another value in that row.

I am trying to display buttons in columns at the end of a row depending on another value in that row. I have found a similar question in the forum and have modified that answer to give me:
columnDefs: [{
// puts a button in the last column
targets: [-1], render: function (a, b, data, d) {
alert("data.accId: " + data.accId + " sessionStorage.getItem('ssAccountID'): " + sessionStorage.getItem('ssAccountID'));
if (data.accId === sessionStorage.getItem('ssAccountID')) {
return "<button type='button' id='deleteCampSite'>Delete</button>";
}
return "";
},
// puts a button in the second last column
targets: [-2], render: function (a, b, data, d) {
if (data.accId === sessionStorage.getItem('ssAccountID')) {
return "<button type='button' id='updateCampSite'>Update</button>";
}
return "";
}
}],
However, that gives me:
How can I get both buttons to show (Delete in last column and Update in second last column) please?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Is this using Editor?
If not, it should work the same for both columns. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi Colin,
This is the test case:
http://live.datatables.net/munalocu/1/
How should it be coded please?
Kind regards,
Glyn
There were a lot of errors in the example. Made the following changes:
render: function (a, b, data, d) {
torender: function (data, type, row) {
. Did this just to follow the Datatables standard parameter naming.if (table.age === 61) {
toif (row[3] == 61) {
. Did this becausetable
is not the variable to use. To access the row data use therow
parameter. This example is using array based data not object sorow[3]
is used to access the age column. Used==
instead of===
to allow for comparing strings to integers.Here is the updated example:
http://live.datatables.net/munalocu/2/edit
Kevin
Thank you Kevin. In my particular case it looks like (in case anyone else needs to know):