Date sorting problem

Date sorting problem

rhemrhem Posts: 4Questions: 1Answers: 0
edited January 2020 in Free community support

Whenever I am trying to sort a column in from the controller in angualrjs, I always get a warning...this is the code, what can i do?

httpAgent.getLoginHistory().then(response => {
        $scope.loginData = response.data;
        $(document).ready(function () {
            $('#table_id').DataTable({
                        columnDefs: [{
                        targets: [2],
                        orderData: [1, 0]
                    }]
                }
            );
        });
    })

Answers

  • kthorngrenkthorngren Posts: 20,320Questions: 26Answers: 4,773

    What is the warning?

    Kevin

  • rhemrhem Posts: 4Questions: 1Answers: 0

    DataTables warning: table id=table_id - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

    this is it, but I have applied the recommended solution and it still gives the same warning

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    You'll get that error when the table is being initialised again - so that getLoginHistory() code is being called more than once. DataTables wouldn't do that when ordering, so it must be something be triggered in Angular.

    Colin

  • rhemrhem Posts: 4Questions: 1Answers: 0
    edited January 2020

    Oh alright, thanks. I'll see what is causing the triggers then.

  • rhemrhem Posts: 4Questions: 1Answers: 0
    edited January 2020

    hi again, i have removed what was causing the trigger, but my date in the third column is not sorting.

        `httpAgent.getLoginHistory().then(response => {
            $scope.loginData = response.data;
            console.log(response.data)
            $.fn.dataTable.moment('dddd, MMMM Do, YYYY');
            $(document).ready(function () {
                $('#table_id').DataTable({
                    columnDefs: [
                    { type: 'date-uk', targets: 2 }
                ],
                    "order": [[2, "asc"]]
                });
            });
        })`
    
  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    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.