Where do I find detailed information about custom buttons

Where do I find detailed information about custom buttons

anoshirianoshiri Posts: 5Questions: 1Answers: 0

Can you point me to how I can implement custom buttons in my table? I need a button to change status of selected items. The documentation is not very clear to me. Meanwhile, I'm running Laravel at the backend.

Thanks in advance.

By the way, great software. I'm enjoying it. It saves me alot of development time.

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Details on how to implement custom buttons are available here. If you have any specific questions about it, please let us know.

    Allan

  • anoshirianoshiri Posts: 5Questions: 1Answers: 0

    Thanks Allan.

    I'm getting an error "Uncaught TypeError: Cannot read property 'rows' of undefined" on this line:

    dt.rows( {selected: true}).data().toArray();

    See code below:

    'buttons' => [
    ['extend' => 'remove','editor' => 'editor', 'text' => '<i class="fa fa-check fa-x5"></i> Activate',
    'formTitle' => 'Activate Batches',
    'formMessage' => 'Are you sure you want to activate these batches?',
    'formButtons' => [
    [ 'text'=> 'Activate', 'action' => 'function ( e, dt, node, config ) {
    var ajaxData = dt.rows( {selected: true}).data().toArray();
    console.log("it works");
    }'
    ],
    [ 'text'=> 'Cancel', 'action'=> 'function () { this.close(); }' ]
    ]],
    ['action'=> 'deactivate', 'text' => '<i class="fa fa-print fa-x5"></i> Deactivate'],
    ]

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Can you give me a link to a page that shows the issue please? That looks like it should work.

    Allan

  • anoshirianoshiri Posts: 5Questions: 1Answers: 0

    I do not have the project online yet. Maybe these screenshots could help.


  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945

    "Uncaught TypeError: Cannot read property 'rows' of undefined" on this line:
    dt.rows( {selected: true}).data().toArray();

    Where have you defined dt?

    Maybe you can post a test case showing the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I got a little confused by the code shown above as well, but the dt appears to be passed in as an argument to the action function:

    'action' => 'function ( e, dt, node, config ) {
    

    That function signature is correct, so that isn't the issue.

    That said, there is somewhere that is calling dt where it isn't defined, and I don't know what that is from the information above. Can you show us your full initialisation code and ideally link to a test case please?

    Allan

  • anoshirianoshiri Posts: 5Questions: 1Answers: 0

    Creating a test case on live.datatables.net is not giving me joy at all. I'm getting JQuery is not defined. Here is the link http://live.datatables.net/weqasate/2/edit

    You believe you can find full code initialisation there.

    Thanks for your help

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I've moved the order of the Javascript around a little: http://live.datatables.net/weqasate/3/edit (load jQuery first, then DataTables and then its extensions).

    Its giving an error about cannot read property style of undefined as the columns array does not contain the same number of columns as the HTML table (6).

    Allan

  • anoshirianoshiri Posts: 5Questions: 1Answers: 0

    I have modified content: http://live.datatables.net/weqasate/5/edit

    Can you review with this?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The Deactivate button is giving an error because it has no action:

    {"action":"deactivate","text":"<i class=\"fa fa-print fa-x5\"><\/i> Deactivate"}

    i.e. when you click it, there is nothing for it to do. That isn't expected in Buttons so it throws an error.

    Allan

This discussion has been closed.