Sorting not working properly when using colums.render

Sorting not working properly when using colums.render

victor881victor881 Posts: 2Questions: 1Answers: 0

I want to add '/kg' behind the price and i tried to achived it by using colums.render and it works just fine but when i try to sort the price colum it didn't sort the right number

this is what try to do to achived it:

columns: [{
data: 'tanggal'
}, {
data: 'produk'
}, {
data: 'harga', // price
render: function(data, type, row, meta) {
return '<span>' + $.fn.dataTable.render.number('.', ',', 2, 'Rp. ').display(data) + ' /kg' + '</span>';
}
}, {
data: ''
}],

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    For this sort of thing you will want to use orthogonal data - e.g.:

    render: function (data, type, row) {
      if (type === 'type' || type === 'sort') {
        return data; // unrendered data for sorting and type detection
      }
      return '<span>' + $.fn.dataTable.render.number('.', ',', 2, 'Rp. ').display(data) + ' /kg' + '</span>';
    }
    

    Allan

  • victor881victor881 Posts: 2Questions: 1Answers: 0
    edited June 2022

    Thanks a lot allan it works like a charm! I really appreciate the help :smiley:

Sign In or Register to comment.