Footer column not showing number aligned right (DT 2.3.3)

Footer column not showing number aligned right (DT 2.3.3)

Wooly65Wooly65 Posts: 98Questions: 30Answers: 1
edited September 1 in Free community support

Link to test case: No

I am surprised I can't find an example showing a numeric column summarized. I was hoping to not have to work up an example.

Description of problem:
In DataTable 2.3.3 my footer numeric columns are left aligned.

I had to add dt-head-left to the numeric and date columns to allow the sort icons to be on the right (suggestion in v2.3.1 fixes)

Looks like the is causing the numeric footer columns to be left justified.

Any suggestions?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 22,261Questions: 26Answers: 5,122

    I built a simple test case:
    https://live.datatables.net/mozuviyo/1/edit

    Looks like the className: 'dt-head-left' option is applied to the footer. According to the styling docs this should only be applied to the header. This rule is being applied:

    table.dataTable thead th.dt-head-left, table.dataTable thead td.dt-head-left, table.dataTable tfoot th.dt-head-left, table.dataTable tfoot td.dt-head-left {
        text-align: left;
    }
    

    One option is to use initComplete to remove the dt-head-left class from the footer, like this example:
    https://live.datatables.net/lukuyode/1/edit

    @allan can comment on whether this is exepcted behavior and if the code or documentation needs fixed.

    Kevin

  • allanallan Posts: 65,056Questions: 1Answers: 10,772 Site admin

    There is an example here.

    I'll need to have a little think about the right course for the class names. Thanks for highlighting that.

    Allan

  • Wooly65Wooly65 Posts: 98Questions: 30Answers: 1

    While you are thinking through the issue I have a related question.

    If there is no data yet for the DataTable the sum value of 0 is shown, but it is aligned to the left and not the the right.

    Here is the example from @kthorngren with the workaround to remove the dt-head-left from the footer via initComplete. I have removed all the data.
    https://live.datatables.net/cifehabi/2/edit

    Here is the image from one of my panels

  • allanallan Posts: 65,056Questions: 1Answers: 10,772 Site admin

    I would expect that to be the case. It can only work out what class should be automatically applied when the data is loaded. Prior to that it will get default alignment. A class name needs to be set for the column in the initialisation or HTML if you know ahead of time what the type is and what the alignment should be.

    Allan

  • kthorngrenkthorngren Posts: 22,261Questions: 26Answers: 5,122

    Inspecting the th it looks like this rule is applied:

    table.dataTable thead th, table.dataTable thead td, table.dataTable tfoot th, table.dataTable tfoot td {
        text-align: left;
    }
    

    You can create a custom CSS to overide the Datatables CSS, like this:

    table.dataTable tfoot th, table.dataTable tfoot td {
        text-align: right;
    }
    

    Updated example.
    https://live.datatables.net/cifehabi/3/edit

    Kevin

  • kthorngrenkthorngren Posts: 22,261Questions: 26Answers: 5,122
    edited September 2 Answer ✓

    Going back to my first test case the th has the class dt-type-numeric applied which causes the number to be right justified:

    <th class="dt-type-numeric" data-dt-column="3" rowspan="1" colspan="1">2415</th>
    

    It looks like with no data type detection doesn't run which means the dt-type-... classes aren't applied. Another option is to apply the dt-type-numeric class using columns.className, for example:
    https://live.datatables.net/cifehabi/4/edit

    I just realized the above selector applies to all the th in the footer. You could make it more specific to just the desired columns. For example:

    table.dataTable tfoot th.dt-footer-right, table.dataTable tfoot td.dt-footer-right {
        text-align: right;
    }
    

    Test case:
    https://live.datatables.net/cozuqule/1/edit

    Note I commented out the initComplete code. This might be a better overall solution.

    Kevin

Sign In or Register to comment.