Display of custom button according to 'recordsTotal' in data

Display of custom button according to 'recordsTotal' in data

Abdullah61Abdullah61 Posts: 2Questions: 1Answers: 0
edited November 2022 in Free community support

Sorry if this question has a solution already answered, I searched a lot but couldn't find it.

I am using server side.
In my example scenario I have a button and I want to control whether that button appears according to the 'recordsTotal' from the ajax response. I want to use buttons.available for this, but the DataTables API that this function takes is not working. Is there a solution to this?

Test case: https://jsbin.com/tobimol/edit?js,console,output

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 17,724Questions: 25Answers: 4,204
    Answer ✓

    Looks like the buttons.buttons.available runs before the asynchronous Ajax response has returned. That is why you see undefined in the console.

    Use initComplete for this. The second parameter is json which has the server side processing response. You can get the recordsTotal value. You can use either button().add() or button().remove() to adjust the buttons based on the recordsTotal value.

    Kevin

  • Abdullah61Abdullah61 Posts: 2Questions: 1Answers: 0

    Thank you, a different perspective is always helpful. :smile:

Sign In or Register to comment.