Add 2 custom buttons inside a cell

Add 2 custom buttons inside a cell

DanaDana Posts: 17Questions: 10Answers: 1
edited February 14 in Free community support

I'm pretty new in working with Datatables and I'm trying to add a new column with two buttons on each cell: a red one with text 'No' on it, that appears anytime and on click does something and a green one with 'OK' text that appears only when ColB minus ColA is +/-10 and on click does something else. My datatable looks something like:

table = $("#datatable-buttons").DataTable({
            data: document.pvm.tableContent(),
            columns: [
            { data: "DateTime", title: "Date\Time" },
            { data: "ColA", title: "ColA" },
            { data: "ColB", title: "ColB" },
            { data: "", title: "Buttons" }
            ],
            fixedHeader: true,
            "bAutoWidth": false,
            "lengthMenu": [[10, 20, 100, 200], [10, 20, 100, 50]],
            "iDisplayLength": 20,
            fixedHeader: true,
            dom: "lfrtiBp",
            "bAutoWidth": false,
            buttons: [
              {
                  extend: "copy",
                  className: "btn-sm"
              },
              {
                  extend: "csv",
                  className: "btn-sm"
              },
              {
                  extend: "excel",
                  className: "btn-sm"
              },
              {
                  extend: "pdf",
                  className: "btn-sm"
              },
              {
                  extend: "print",
                  className: "btn-sm"
              },
            ],
            "order": [[0, "desc"]],
            "columnDefs": [ {
                "targets": -1,
                "data": null,
                "defaultContent": "<button color='red'>Click!</button>"
             } ]
            }
        });

I've tried first by adding the red button but it doesn't work :( Is there a way to add those two buttons?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 875Questions: 0Answers: 168
    Answer ✓

    Hi Dana,

    A very similar question was asked yesterday (though it was for just a single button). But the example posted there would point you in the right direction.

    Cheers,

    Colin

Sign In or Register to comment.