aoColumnDefs + columnDefs

aoColumnDefs + columnDefs

Alex2019Alex2019 Posts: 62Questions: 9Answers: 0

Hi,

i have this code which works great // hide column but filter enable

"aoColumnDefs": [{ "bSearchable": true, "bVisible": false, "aTargets": [ 10 ] },] 

but if I go to insert this too the code above doesn't work

"columnDefs": [  // 
      {
        "targets": 3,
        "render": function (data, type, row, meta) {
          if (type === 'display') {
            var label = 'label-success';
            if (data > 30 && data < 60) {
              label = 'label-warning';
            } else if (data > 60) {
              label = 'label-danger';
            }
            return '<span class="label ' + label + '">' + data + '</span>';
          }
          return data;
        }
      }
    ]

in this way

"aoColumnDefs": [{ "bSearchable": true, "bVisible": false, "aTargets": [ 10 ] },] 

"columnDefs": [  // 
      {
        "targets": 3,
        "render": function (data, type, row, meta) {
          if (type === 'display') {
            var label = 'label-success';
            if (data > 30 && data < 60) {
              label = 'label-warning';
            } else if (data > 60) {
              label = 'label-danger';
            }
            return '<span class="label ' + label + '">' + data + '</span>';
          }
          return data;
        }
      }
    ]

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    They are both the same option. The aoColumnDefs is the legacy form of the option from Datatables 1.9. The columnDefs is the current form. See this Conversion Guide for more details.

    One option is overwriting the other. Combine them into one columnDefs option. Its suggested that you use the current instead of the legacy form of the options.

    Kevin

  • Alex2019Alex2019 Posts: 62Questions: 9Answers: 0

    Hi kthorngren

    sorry, but I'm not a programmer, :(
    just hobbies, I'm trying to learn,

    explain me how to fix my code

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    This is what you want:

    "columnDefs": [  //
          { "bSearchable": true, "bVisible": false, "aTargets": [ 10 ] },
          {
            "targets": 3,
            "render": function (data, type, row, meta) {
              if (type === 'display') {
                var label = 'label-success';
                if (data > 30 && data < 60) {
                  label = 'label-warning';
                } else if (data > 60) {
                  label = 'label-danger';
                }
                return '<span class="label ' + label + '">' + data + '</span>';
              }
              return data;
            }
          }
        ]
    

    Kevin

  • Alex2019Alex2019 Posts: 62Questions: 9Answers: 0

    Thank you kthorngren :)

This discussion has been closed.