Using rowCallback to vary the Render Function

Using rowCallback to vary the Render Function

andrew beeverandrew beever Posts: 12Questions: 6Answers: 0

I am very new to Datatables and Developing and would be delighted for a few pointers please

I have a column in a table as below. It renders with +/- buttons to vary the quantity which all works fine (except the text alignment??).

data: "in_qty",
        classname: "dtTextCenter",
        render: function (data, type, row) {
          if (type === "display") {
            return (
              data +
              `<div>
              <i class="fa fa-plus-circle inc changeVal"></i>
              <i class="fa fa-minus-circle dec changeVal"></i>
            </div>`
            );
          }
          return data;
        },

For some rows I don't want the +/- buttons displayed dependent on the value in another column

Is it possible to hide the buttons using rowCallback

rowCallback: function (row, data, index) {
      if (data.has_sn == "1") {
        //Don't show +/- Buttons
      }
    } 

Thanks in anticipation

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    You could do that still in your first code block. The third parameter in your code columns.render is row, which is the data for the entire row - so you can do a test on that and return an empty string when you don't want the buttons.

    Colin

  • andrew beeverandrew beever Posts: 12Questions: 6Answers: 0

    Thank you so much!

This discussion has been closed.