columnDefs render type == 'filter' does not returned desired data

columnDefs render type == 'filter' does not returned desired data

LeftPinkieLeftPinkie Posts: 6Questions: 4Answers: 0

So I have the following data from server-side processing...

[
  {
    "type": "percent",
    "value": 50
  },
  {
    "type": "dollar",
    "value": 5050
  }
]

My columnDefs is...

columnDefs: [
  {
    targets: 0 ,
    name: 'value' ,
    data: 'value' ,
    render: function( $data , $type , $row ) {
      if ( $type == 'display' ) {
        if ( $row.type == 'percent' ) {
          return $data + '%' ;
        } else if ( $row.type == 'dollar' ) {
          return '$' + Math.floor( $data / 100 ) + '.' + ( '00' + ( $data % 100 ) ).slice( -2 ) ;
        } else {
          return '' ;
        }
      } else if ( $type == 'filter' ) {
        if ( $row.type == 'percent' ) {
          return $data + '%' ;
        } else if ( $row.type == 'dollar' ) {
          return '$' + Math.floor( $data / 100 ) + '.' + ( '00' + ( $data % 100 ) ).slice( -2 ) ;
        } else {
          return '' ;
        }
      } else {
        return $data ;
      } ;
    } ,
    className: 'text-right'
  }
]

Using columnDefs.render.type='display' I am able to correctly display the data as such...

50%
$50.50

However, I cannot filter on the correct data. Filtering for 50.50 returns nothing, but filtering for 5050 will return $50.50. What am I doing wrong?

This question has an accepted answers - jump to answer

Answers

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

    Hi @LeftPinkie ,

    We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • LeftPinkieLeftPinkie Posts: 6Questions: 4Answers: 0

    I was able to figure it out... had a typo in one of my render anonymous function.

This discussion has been closed.