1

I try to create a Datatable using JQuery and sort it based on the first column. This column contains both links and plain text.

JQuery apparently sorts them separately, so first the links alphabetically and below the plain text alphabetically.

How can I mix them together, so that every text format is considered the same? I already tried a bunch of solutions, including column-type definition, custom order definition... None of them works properly.

$(document).ready(function () {
        $('#toollist').dataTable({
            "iDisplayLength": 10,
            "scrollY": "500px",
            "scrollCollapse": true,
            "lengthMenu": [5, 10, 25, 50, 100],
        });
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css"/>

<table id="toollist" class="table display table-bordered">
    <thead>
    <tr>
        <th>Column 1</th>
        <th>Column 2</th>
        <th>Column 3</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>
            <a href="https://www.google.com">
                <strong>A</strong></a></td>
        <td>B</td>
        <td>C</td>
    </tr>
    <tr>
        <td>
            <strong>A</strong></td>
        <td>B</td>
        <td>C</td>
    </tr>
    <tr>
        <td>
            <strong>B</strong></td>
        <td>C</td>
        <td>D</td>
    </tr>
    <tr>
        <td>
            <a href="https://www.google.com">
                <strong>B</strong></a></td>
        <td>C</td>
        <td>D</td>
    </tr>
    <tr>
        <td>
            <a href="https://www.google.com">
                <strong>C</strong></a></td>
        <td>D</td>
        <td>E</td>
    </tr>
    <tr>
        <td>
            <strong>C</strong></td>
        <td>D</td>
        <td>E</td>
    </tr>
    </tbody>
</table>​

14
  • I think you might find your solution here: datatables.net/development/sorting Commented Jul 11, 2017 at 19:31
  • Thanks for your link. Unfortunately I tried this one before and it doesn't work :( Commented Jul 11, 2017 at 20:04
  • Is it possible that you've added something to your code that breaks the default behavior? Commented Jul 11, 2017 at 20:05
  • The posted Code snippet is all thats in the code Commented Jul 11, 2017 at 20:06
  • I also tried letting out Bootstrap, but that doesn't make any difference Commented Jul 11, 2017 at 20:09

1 Answer 1

0

It is a Sharepoint specific charset issue. The answer to the problem is on following Datatables forum feed: https://datatables.net/forums/discussion/43509/links-and-plain-text-are-sorted-separately#latest

However, there is also a very helpful sorting plugin posted from allan.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.