How to redraw datatable on href onclick?
How to redraw datatable on href onclick?
I have a column that generates green checkmark links if data == true, else it generates red X links. When one of the links is clicked, it should call my "Set" method and then redraw my paymentDataTable.
I have tried the following, which does redraw my paymentDataTable, but my "Set" method is not called and therefore, the data is not updated:
{
data: "HasPayment",
render: function (data, type, row) {
var paymentSet = '@Url.Action("Set", "Payment")?applicationId=' + row.Id + '&year=' + row.Year + '&month=' + row.Month + '&hasPayment=' + data;
if (data) {
return '<a href=\"' + paymentSet + '\" onclick="paymentDataTable.draw(); return false;" class="fas fa-solid fa-check" style="color: green"></a>';
}
return '<a href=\"' + paymentSet + '\" onclick="paymentDataTable.draw(); return false;" class="fas fa-solid fa-times" style="color: red"></a>';
}
},
I have also tried the following, which does call my "Set" method and updates the data, but it navigates to another page:
{
data: "HasPayment",
render: function (data, type, row) {
var paymentSet = '@Url.Action("Set", "Payment")?applicationId=' + row.Id + '&year=' + row.Year + '&month=' + row.Month + '&hasPayment=' + data;
if (data) {
return '<a href=\"' + paymentSet + '\" onclick="paymentDataTable.draw();" class="fas fa-solid fa-check" style="color: green"></a>';
}
return '<a href=\"' + paymentSet + '\" onclick="paymentDataTable.draw();" class="fas fa-solid fa-times" style="color: red"></a>';
}
},
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
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