modify sort feature on column

modify sort feature on column

jschroeder7jschroeder7 Posts: 22Questions: 11Answers: 0

Is it possible to modify/define what is sorted on the sort feature here in data-column-index="2" "bookmark/topic"?

I would like to sort by bookmark or topic.
For example, Topic 1 is "topic" and so is "mind", but Galatians 5:1 NKJV is a bookmark.

Both of these have been merged into one column:
bookmark.reference
topic.name


Answers

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    There are a few options that come to mind:

    1. Create an additional column that defines if the data is a topic or bookmark. Use columns.visible to hide the column. Use columns.orderData to order the table by the hidden column followed by the Bookmark/Topic column when the user sorts the Bookmark/Topic column.
    2. Use Orthogonal data to set the value for the sort process.
    3. Create an Ordering plugin.

    Option 1 might be the easiest. Options 2 and 3 would need a way to determine if the data is a topic or bookmark.

    If you need help with these please provide a simple test case with an example of your data so we can collaborate on the code.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • jschroeder7jschroeder7 Posts: 22Questions: 11Answers: 0

    @kthorngren

    Thank you for your reply. Is this a possible 4th option? Per my snapshots attached? I was able to get a dropdown box there. However, it disappears when I start to search for something. And it doesn't have logic to it.

    I put this code into accomplish the dropdown box.

    $('<div class="pull-right">' +
            '<select class="form-group">'+
                '<option value="bookmark">Bookmark</option>'+
                '<option value="topic">Topic</option>'+
                    '</select>' + 
            '</div>').appendTo("#notes-datatable_wrapper .dataTables_info");
    
        $(".dataTables_info label").addClass("pull-right");
    
  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    Oh, I thought in your first post you were asking about sorting. This example shows a technique you can use to add your select list into the Datatables toolbar.

    I would probably go with the first option with the hidden column but you don't need to worry about the columns.orderData. Create a change event handler for the select options. In the event handler use column().search() to search the hidden column which will contain either topic or bookmark.

    See this example to get an idea.

    Kevin

Sign In or Register to comment.