Add columns.type num-fmt custom order info

Add columns.type num-fmt custom order info

islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
edited May 2018 in Free community support

How can I add to columns.type type num-fmt more sorting data like a spacebar and a . for example? So it would sort something similar to 10 908.36 €?

Replies

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    Also how to tell it something like : ignore everything after a slash for example. As if I have 100.00 % / 31 qte, I would it to treat this as a number 100.00 % and ignore everything after the /. Thanks! :smile:

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

    HI @islamelshobokshy ,

    If you want to ignore part of the cell data, the best bet would be to render it with columns.render and return a sanitised version for type sort - that way you can strip it of anything you don't want and it'll just use the default searching. If you want to go down the route of custom sorting, you can create your own fairly easily - look at the existing example under here to get an idea of what to do.

    Cheers,

    Colin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    edited May 2018

    Could you please write to me an example of a returned type sort sanitised version? As I have no idea how to do that, even after reading the full columns.render page :smiley: And I also tried looking at the custom sorting, it seems quite complicated :( Isn't there a simple way to add 2 more things for it to take into consideration rather than doing something that complicated? I just want it to take spacebars and dots when it is looking at the string...

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited May 2018

    This example here from that page is for type display:

        "render": function ( data, type, row, meta ) {
          return type === 'display' && data.length > 40 ?
            '<span title="'+data+'">'+data.substr( 0, 38 )+'...</span>' :
            data;
        }
    

    To change your string for sort, it would be very similar - you'd test for sort, then manipulate and return the string to match the format you want.

    For simply having space for the thousands separator, you could use the internationalisation capabilities, the language.thousands.

    Cheers,

    Colin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    edited May 2018

    The thousands langage separator doesn't work, the sorting still doesn't take the space into consideration :/

    language: {
        thousands: " ", // "&nbsp;" doesn't work either
    }
    
  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    edited May 2018

    As for the sorting I figured it out as you said (thanks!), I'll post it here for reference :

    {
        "targets": 0, 
        "render": function ( data, type, row, meta ) {
            console.log(data.split('%')[0]);
            return type === 'sort' ?
                data.split('/')[0] : data;
        }
    }
    
This discussion has been closed.