columnFilter Plugin - Callbacks available? - Need to SUM col from filtered results.

columnFilter Plugin - Callbacks available? - Need to SUM col from filtered results.

btBillbtBill Posts: 31Questions: 0Answers: 0
edited July 2013 in Plug-ins
Using:
* File: jquery.dataTables.columnFilter.js
* Version: 1.5.1.
* Author: Jovan Popovic

DT: 1.10.dev from git.
Scroller 1.1.1 from git.

I need to SUM a col from the table once it's filtered and display this sum in the footer.

I have click events summing the selected rows, but when the filter is run, it doesnt update correctly.

Right now, I have taken the default columnFilter plugin and just moved the input fields by the dom to a floating div. It works well, but I need to automatically adjust the total based on the fitlering, also, need to uncheck the checkboxes if there are any checked.

I hope this gives enough info, if not, i will provide more. I just feel like I am not using the right method.

Thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    edited July 2013
    Can't say about the column filter plug-in (its 3rd party and not supported by myself), but:

    > I need to SUM a col from the table once it's filtered and display this sum in the footer.

    In DataTables 1.10 you can simply do:

    [code]
    var sum = table.column( 0, {filter:'applied'} ).data().reduce( function ( a, b ) {
    return a + b;
    } );
    [/code]

    Stick that into a draw callback function and that should do it (changing the column selector for the column you want of course).

    Allan
  • btBillbtBill Posts: 31Questions: 0Answers: 0
    [quote]allan said: Can't say about the column filter plug-in (its 3rd party and not supported by myself), but:[/quote]

    So is the example you provided using the columnFilter plugin? I think there is built in filtering to DT as well, right?

    I get 'column' is not a function.
    Just trying to determine if the filtering I;m using (the plugin) is causing this.

    Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    This example is provided by myself: http://datatables.net/release-datatables/examples/api/multi_filter.html .

    The plug-in called "columnFilter" is not - its third party code, kindly provided by Jovan Popovic as noted in the file header you linked to.

    I've not tried that plug-in in 1.10 and I've no idea if it will work with 1.10 I'm afraid.

    Allan
  • btBillbtBill Posts: 31Questions: 0Answers: 0
    Ah, ok. got it.
    I kind of have this working now. I had to comment out the Info section that the scroller was outputting to get the fnInfoCallback to fire correctly.

    so I have this working now, but....
    my headers seem to not line up properly with the columns.
    When I click on a row (which fires an fnDraw) it lines up much closer...still not exact, but closer.
    Hopefully I will get this squared away today.

    Thanks for the response. i will post back with more info as I go.
This discussion has been closed.