Sorting DataTable

Sorting DataTable

ArgaWoWArgaWoW Posts: 14Questions: 5Answers: 0

Hi all,

I am have a column that has an integer value. Depending on the value I am render a string instead.

When I am trying to sort this column it seems it use the render value for sorting. Is there the posibility to use the data behind for rendering?

e.g.:

data: 1 => render: "Rahmenprofil"
data: 2 => render: "Rahmenteil"
data: 3 => render: "Flügelprofil"
data: 4 => render: "Flügelteilt"

I am using:
order: [
[11, "asc"]
]

but I get as result

Rahmenteil
Rahmenprofil
Flügelteil
Flügelprofil

I hope some one can help me to get the right ordering for my data.

Thanks a lot for any advice :)

Arga

Answers

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @ArgaWoW ,

    There are a couple of ways that you could do this. You could use columns.render to set the data for the sort property there. You could also create a sorting plugin to identify the numbers and then return the relevant data, take a look at this example which is doing something similar.

    Thanks,
    Sandy

  • ArgaWoWArgaWoW Posts: 14Questions: 5Answers: 0

    Hi @sandy,

    thank you very much for your answer.

    I will try the plugin :smile:

    Perhaps,
    please can you give me an example how to do the ordering within the Columns.Render option. ?

    Thanks a lot again

    CU Araga

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

    Here's an example of that ordering,

    Colin

  • ArgaWoWArgaWoW Posts: 14Questions: 5Answers: 0

    Hi Colin,

    thanks a lot for you answer, but it dont work for me.

    Here is my code:

    ` columnDefs: [

                        //0: id
                        //1: addByUser
                        //2: Artikelnummer
                        //3: Bezeichnung1
                        //4: Menge
                        //5: Mengeneinheit
                        //6: Profillänge
                        //7: Winkel1L
                        //8: Winkel2L
                        //9: Winkel1R
                        //10: Winkel2R
                        //11: StueliPos
                        //12: In Zubehör
                        //13: In Zuschnitt
                        //14: Is Baugruppe   
                        //15: Image
    
                        {
                            targets: 11,
                            render: function (data, type, row, meta) {
                                console.log("test");
                                if (type === 'sort') {
                                    switch (data) {
                                        case 'Rahmenprofil':
                                            return 0;
                                        case 'Rahmenteil':
                                            return 1;
                                        case 'Flügelprofil':
                                            return 2;
                                        case 'Flügelteil':
                                            return 3;
                                    }
                                }
                                return data;
                            }
                        }
    ]
    

    `
    I have add a log to the console, but it seems the code dont enter the function.

    Any idea?

    Again, thanks for your help :)

    Arga

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Could you give us a link to your page - that looks like it should work. Unless you are using server-side processing perhaps? If you are (serverSide), then whatever script you are using at the server-side is responsible for doing the sorting.

    Allan

  • ArgaWoWArgaWoW Posts: 14Questions: 5Answers: 0
    edited September 2020

    Hi Allan,

    whats the ways you would access my side?
    Would you accept an teams sessions to look on my maschine?
    Would be the easiest and fastest way to show you my code :smile:

    If you agree, sen me a pm :wink:

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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

This discussion has been closed.