Unable to sort footer selection dropdown month name wise

Unable to sort footer selection dropdown month name wise

amitdurgapuramitdurgapur Posts: 3Questions: 1Answers: 0

Sorry I am new here and don't know how to ask queries.

I have a salary table. there is a column by which users can see the data of employees in monthwise. I have used the example in https://www.datatables.net/examples/api/multi_filter_select.html. But in the footer portion, it is showing the month name in alphabetical order, but I want it in January, February..... December.

My HTML code is

Name Month Year Total salary <?php } ?>
Akash December 2020 500
Sumit March 2020 600
Akash January 2020 500
Sumit April 2020 500
Sumit May 2020 500
Akash February 2020 500
Sumit January 2020 500
Akash October 2020 500
Name Month Year Total salary

This question has an accepted answers - jump to answer

Answers

  • 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

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    This code from the example sorts the select list:

                    column.data().unique().sort().each( function ( d, j ) {
                        select.append( '<option value="'+d+'">'+d+'</option>' )
                    } );
    

    You will need to use a different Javascript technique to order the months the way you want. Take a look on Stack Overflow for suggestions if you need. You can use column().index() in an if statement to decide which code to use for the select list, for example:

    var myMonthCol = 1;  // Column index of Month column
    if ( column.index() === myMonthCol ) { 
      // Code to build sorted month select list
    } else {
      column.data().unique().sort().each( function ( d, j ) {
        select.append( '<option value="'+d+'">'+d+'</option>' )
      } );
    }
    

    If you need help then please provide the test case Colin asked for.

    Kevin

  • amitdurgapuramitdurgapur Posts: 3Questions: 1Answers: 0

    Ihave uploaded the test case in the following

    http://live.datatables.net/rowufiru/1/

    I want the footer month not to appear in alphabetical order. It should appear in
    January
    February
    March
    ....
    December

    in this way.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited September 2020 Answer ✓

    Thanks for the test case. I found this SO thread and modified the code in the first response a bit for this example:
    http://live.datatables.net/hatovucu/1/edit

    Kevin

  • amitdurgapuramitdurgapur Posts: 3Questions: 1Answers: 0

    Wow you save my life. Thank you very much.

This discussion has been closed.