Disable double click on arrow key in datatables

Disable double click on arrow key in datatables

iamamitaiamamita Posts: 14Questions: 2Answers: 0

I have a table. If I click 1st time on column header then it should sort the column in provided order. If I am clicking again 2nd or more times on column header then it shouldn't do anything.

Note: I want to preserve 1st click sorting order.

Answers

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416

    As far as I can see you can't turn off ordering dynamically using the API.
    There was something like "column().orderable()". You can still find it with the search, but the link doesn't lead anywhere.

    So if the API doesn't support it you can try to hide the ordering arrows using jQuery after the first click.

  • iamamitaiamamita Posts: 14Questions: 2Answers: 0

    okay, as I am backend developer and totally new to frontend so can you please provide the code to hide the arrow keys after the first click.

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416

    No, sorry. This is not a coding service.

    You should either become a front end developer quickly (I did that as well a couple of years ago) or hire a front end developer.

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922
    edited April 2020

    I think you probably don't want to hide the ordering arrows as they show the order of the table. Sounds like you will want to turn off the click event listener on the clicked column. One way to do this is to create a 'click' event handler before Datatables is initialized. Datatables will then add its click handlers which will be executed second. This example shows disabling the click handler after sorting the first column:
    http://live.datatables.net/covefato/1/edit

    Its specific to column 0 due to the selector th:eq(0). You can remove the :eq(0) to affect the whole header or change the number to match the column. You will want to become familiar with this page as it will be very useful with Datatables:
    https://api.jquery.com/category/selectors/

    Kevin

  • iamamitaiamamita Posts: 14Questions: 2Answers: 0
    edited April 2020

    Thanks a lot, it's working but it disables the clicks on other columns as well.
    I don't want that. My scenario is sorting applies on every column. Suppose I have 3 columns and i clicked on first column arrow key then it disables for the second click but other two columns click should work. Same case with the other two columns so columns are also not fixed that only first column click should disable.

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922

    it's working but it disables the clicks on other columns as well.

    In the example I provided the only column the click even tis disabled on is the first one. I'm able to click on the others. Does that not work for you?

    Kevin

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922

    Based on your other thread this may not be what you want to do. See my response there for more info.

    Kevin

  • iamamitaiamamita Posts: 14Questions: 2Answers: 0

    No, It didn't work.

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922

    The example isn't working or the code isn't working on your page?

    I click on the Name column, it sorts then I can't click on it again. But I can sort any other column.

    Kevin

  • iamamitaiamamita Posts: 14Questions: 2Answers: 0

    Yes, but I am unable to sort other columns as well

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922

    I'm not sure why its not working for you. Maybe a browser issue. I use Chrome. But it might not matter since this is probably not what you want for the solution.

    Kevin

  • 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.