How to select (and copy) a column name?

How to select (and copy) a column name?

mwoutsmwouts Posts: 19Questions: 3Answers: 0

Hi Allan, I would like to know if it is possible to reduce the size of the ordering button in the table header to allow the column names to be selected (e.g. double click as we do for text) and copied (e.g. Ctrl+C) ?

That is in the context of ITables, where we write Python code to display a table, then look at the table, and use the output to edit the Python code, often adding conditions that involve the columns names.

I looked into this in the past at https://github.com/mwouts/itables/issues/227, and found that setting orderable=False on the columns was one way to do it, but ideally I would prefer to be able to both sort and still copy the column name.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited April 23 Answer ✓

    Are you using Datatables 2.0? If so it looks like you can use order.listener() to apply the listeners to the sort icons. Take a look at this example and you will see there is a new data-dt-order attribute that can be applied to the -tag th` to disable ordering or display the icon only. I built this example to show how it might work:
    https://live.datatables.net/febasito/1/edit

    The th now has a data-dt-column attribute with the column index. Use that as part of the selector to find the specific column's order icon for order.listener(). Use the browser's inspector to see the structure of the header.

    However if you have a previous version of Datatables then see the two threads linked to by Colin in this thread for ideas.

    Kevin

  • mwoutsmwouts Posts: 19Questions: 3Answers: 0

    Thank you Kevin! Yes the example achieves what I am looking for - I can double click on "Name" in the first column and it becomes selected. And I confirm that I am using DataTables 2.0.

    However I am not sure I can really use this in the context of ITables - I prefer to use as little JS as possible on my end. So, rather than setting data-dt-order="icon-only" on every column, and then setting a callback that restores the sorting, do you think I could ask for a global option on DataTables that would let the column text selectable and restrict the sorting to the icon? Thanks!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    It isn't something I'm planning to add to DataTables core - at least not yet. But I an planning a new extension that will do something basically like what you are looking for (it might require a new option in DataTables core, I'm not yet sure).

    At the moment, you'd need to use order.listener() on the element you want the sorting to activate on, as Kevin suggests.

    Allan

  • mwoutsmwouts Posts: 19Questions: 3Answers: 0

    Makes sense - Thanks Allan! Looking forward to it. Thanks Kevin for the workaround in the meantime.

Sign In or Register to comment.