Even doing "orderable": false, "targets": 0 doesnt stop the first collum for being ordered

Even doing "orderable": false, "targets": 0 doesnt stop the first collum for being ordered

User123456User123456 Posts: 57Questions: 15Answers: 0
edited August 2017 in Free community support

The command:

$(document).ready(function() {
        var table = $('#publicationTable').DataTable( {
    ...

"columnDefs": [ 
            { "orderable": false, "targets": 0 },
            { "orderable": false, "targets": 7 },
            ],

...

And the table structure:

<table id="publicationTable" class="table table-striped table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th>Título</th>
                                                    <th>Tipo</th>
                                                    <th>Ano</th>
                                                    <th>Competência</th>
                                                    <th>Razão Social</th>
                                                    <th>Empregado</th>
                                                    <th></th>
                                                </tr>
                                            </thead>
                                        </table>

I'm Still being able to sort the first collum, but not the last. Why?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,332Questions: 26Answers: 4,951

    Are you saying that you can click the header of the first column and change the order?

    Or that the column is ordered when the table is loaded?

    If the second then you need to set the order to order the table the way you want. It defaults to ordering the first column by ascending.

    Kevin

  • User123456User123456 Posts: 57Questions: 15Answers: 0
    edited August 2017

    The first option @kthorngren. I can click the header of the first collum and change order. Even using the code above.

  • kthorngrenkthorngren Posts: 21,332Questions: 26Answers: 4,951

    I copied your code into this test case and it works. Meaning clicking on the first column does not change the order.

    Maybe you can share more of your code or provide a link or test case showing the issue.

    Kevin

  • User123456User123456 Posts: 57Questions: 15Answers: 0
    edited August 2017

    @kthorngren, the bin isn't working for me.

    See the image for a better comprehension. Using this same code it's possible to order the table clicking.

    This is the code to initialize the datatables plugin:

    $(document).ready(function() {
            var table = $('#publicationTable').DataTable( {
                lengthChange: true,
            ajax: {
                url: "lib/publicationProcessing.php",
                type: "POST"
            },
            serverSide: true,
                columns: [
                    { data: "p.status",
                    render: function ( data, type, row ) {
                        var text = "";
                        if (type == "display") {
                            if (data == "1") {
                                text = "<i class='ace-icon fa fa-circle green'></i>";
                            } else {
                                text = "<i class='ace-icon fa fa-circle red'></i>";
                            }
                            data = text
                        }
                        return data;
                    }
                },
                    { data: "ti.PublicationTitle" },
                    { data: "ty.PublicationType" },
                    { data: "p.ano" },
                    { data: "p.competencia" },
                    { data: "c.razaoSocial" },
                    { data: "e.nome" },
    
                    { data: null,
                    render: function(data, type, full){
                    return '<a data-toggle="modal" data-target="#infoModal" data-id="' + full.p.id_Publication + '" id="getPublication" class="blue"><i class="ace-icon fa fa-search-plus bigger-130"></i></a> <a class="red" href="deletePublication.php?id_Publication=' + full.p.id_Publication + '"><i class="ace-icon fa fa-trash-o bigger-130"></i></a> <a class="orange" href="' + full.p.path + full.p.arquivo +'" target="_blank"><i class="ace-icon fa fa-download bigger-130"></i></a>';
                }
                }
                ],
    
                "columnDefs": [ 
                { "orderable": false, "targets": 0 },
                { "orderable": false, "targets": 7 },
                ],
    
                "sScrollX": "100%",
                "sScrollXInner": "115%",
            } );
        } );
    
  • User123456User123456 Posts: 57Questions: 15Answers: 0

    @kthorngren, I don't know why, but I realized now that, its not sorting/ordering. It's clickabe but it's not ordering the first collum. I can click but nothing happens.

    If I click in the header of other collum (except for 0 and 7) its ordered and the first icon disappear. Strange, is there a way to fix this?

  • kthorngrenkthorngren Posts: 21,332Questions: 26Answers: 4,951
    Answer ✓

    Like I said the default order of the table is the first column ascending. Reading the columns.orderable docs it states:

    Note that this option only effects the end user's ability to order a column. Developers are still able to order a column using the "order" option or the "order()" method if required.

    The upward arrow is there because that is the column that is being sorted. If you want to change this you can use order to select the column or columns you prefer to have ordered on initialization.

    Kevin

This discussion has been closed.