Page 1 of 1

DataTable Custom Button per Rows

Posted: 18 Jan 2023, 18:33
by dylan.ramirez
Hi,

Can anyone try to add custom button to a data table or change its column type to hyperlink to redirect or get data of specific row?

Thanks for helping and giving opinion.

Re: DataTable Custom Button per Rows

Posted: 19 Jan 2023, 03:24
by Dino
Hi,

While the use of datatables in aXes is mostly to just display data not really to interact with it,
according to this example:
https://datatables.net/examples/ajax/nu ... ource.html

you basically have to use this for columnDefs to get a button there:

Code: Select all

columnDefs: [
            {
                targets: -1,
                data: null,
                defaultContent: '<button>Click!</button>',
            },
which translates to aXes to go to columnDefs, edit it and put this code there:
datatables01.png
datatables01.png (146.33 KiB) Viewed 6025 times

Code: Select all

ENV.returnValue =  [
    {
        targets: -1,
        data: null,
        defaultContent: '<button>Click!</button>',
    },
];
to get this result:
datatables02.png
datatables02.png (88.64 KiB) Viewed 6025 times
now what to do with the onclick action and where to put that no idea but is supposed to be a code like this:

Code: Select all

$('#example tbody').on('click', 'button', function () {
        var data = table.row($(this).parents('tr')).data();
        alert(data[0] + "'s salary is: " + data[5]);
    });
.

Re: DataTable Custom Button per Rows

Posted: 19 Jan 2023, 12:25
by dylan.ramirez
thanks for the help! I appreciate.