TypeScript- pass ButtonConfigCommon into DataTable

TypeScript- pass ButtonConfigCommon into DataTable

spownerspowner Posts: 2Questions: 2Answers: 0
edited February 2023 in Free community support

Hello,
I have problem to pass ButtonConfigCommon into DataTable... I am not sure, if it is bug, feature or am I doing something wrong?

Example:

class EditButton implements ButtonConfigCommon {
    className?: string = 'btn btn-primary';
}

const editButton = new EditButton();

const table = new DataTable('#example', {
        lengthMenu: [10, 20, 50, 75, 100],
        rowId: 'staffId',
        dom: 'Bfrtip',
        buttons: [editButton]
    });
}

Problem is that editButton is not passing this ajax function comparsion (dataTables.buttons.mjs line 1069):

$.isPlainObject(base)

Code crash on error Uncaught Buttons: Too many iterations ( (dataTables.buttons.mjs line 1092) , possible solution to this is convert object to plain object:

 buttons: [JSON.parse(JSON.stringify(editButton))]

But is this right approach? Is there any better solution? Is it possible to pass ButtonConfigCommon without conversion?

Thanks.

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    ButtonConfigCommon is a TypeScript interface, it doesn't actually get passed around anywhere in Javascript. If you are getting a too many iterations error, that isn't a Typescript error, but rather an executing Javascript one.

    Perhaps you can show me what EditButton does, or even better, link to a repo or a StackBltiz example showing the issue please?

    Allan

Sign In or Register to comment.