Rowgroups with enum sorting

Rowgroups with enum sorting

rossmere67rossmere67 Posts: 3Questions: 1Answers: 0

Enum sorting works without rowgroup; must as soon as combine them I get an error that "A" is not a function. I know according to the rowgroup extension docs there are some limitations but I couldn't see custom sorting as one. Is this a bug?

   $.fn.dataTable.enum(['Revenue', 'Expenses', 'Assets', 'Liabilities', 'Equity', 'System Controls']);

    $("table.report").DataTable({
        paging: false,
        dom: "t",
        order: [
            [2, 'enum'],
            [1, 'asc'],
        ],
        rowGroup: {
            dataSrc: [2, 1],
            emptyDataGroup: null
        },
        columnDefs: [
            {
                type: "enum",
                targets: [2]
            },
            { 
                targets: [1,2], visible: false
            },
        ],
    });

Answers

  • rossmere67rossmere67 Posts: 3Questions: 1Answers: 0

    Apologies, I am getting the error it seems without rowgroup. So this gives the same error -

       $.fn.dataTable.enum(['Revenue', 'Expenses', 'Assets', 'Liabilities', 'Equity','System Controls']);
    
        $("table.report").DataTable({
            paging: false,
            dom: "t",
            order: [
                [2, 'enum'],
                [1, 'asc'],
            ],
            columnDefs: [
                {
                    type: "enum",
                    targets: [2]
                },
            ],
        });
    
  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923
    edited January 2021

    Not sure why you are getting the error "A" is not a function. But you do have a couple issues.

    First is this:

         order: [
             [2, 'enum'],
             [1, 'asc'],
         ],
    

    According to the order docs you can supply asc or desc for the order:

    Direction so order to apply (asc for ascending order or desc for descending order).

    Instead of using enum you need to either use asc or desc.

    Second Datatables automatic type detection will determine if one or more columns will determine if the column matches the enum array. If all the values in the column are found in the array then it will automatically type it as enum. If not it will type it appropriately as described in the columns.type docs. Likely you will need to remove type: "enum", to allow auto detection to work. If you assing it the column might not be assigned to the enum type and be sorted using a different type.

    See this example of using enum on the Office column. See the order option. Try uncommenting the type: 'enum' to see that the ordering doesn't work as expected.
    http://live.datatables.net/sosolaco/1/edit

    If all this doesn't help then please provide a link to your page or a test case replicating the issue so we can help debug:
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • rossmere67rossmere67 Posts: 3Questions: 1Answers: 0

    Thanks for the feedback. I've solved the problem now -

        $.fn.dataTable.enum(['Revenue', 'Expenses', 'Assets', 'Liabilities', 'Equity', 'System Controls']);
        $("table.report").DataTable({
            paging: false,
            dom: "t",
            rowGroup: {
                dataSrc: [2, 1],
                emptyDataGroup: null
            },
            order: [
                [2, 'asc'],
            ],
            columnDefs: [
                { 
                    targets: [1, 2], visible: false
                },
            ],
        });
    

    I didn't realise it was clever enough to work all this out.

This discussion has been closed.