Column sum by column name

Column sum by column name

efremovefremov Posts: 1Questions: 1Answers: 0

I using this Sum plugin (https://datatables.net/plug-ins/api/sum()
Can I calculate sum based on COLUMN NAME instead of column index??

var api = this.api();
      $( api.table().footer() ).html(
        api.column( 4, {page:'current'} ).data().sum()
      );

Answers

  • colincolin Posts: 875Questions: 0Answers: 168

    Hi @efremov ,

    Yep, that's just the column-selector, see this link here on how to specified named columns.

    Cheers,

    Colin

  • vivalazvivalaz Posts: 7Questions: 4Answers: 0

    Hi! It doesnt works. Look at my code, please. I use this function in drawCallback
    var api = this.api(), data; api.column('fraht_nal:name', {filter: 'applied'}).data() returns undefined

  • colincolin Posts: 875Questions: 0Answers: 168

    Hi @vivalaz ,

    Yep, that's definitely correct, see the example here. Note, filter is only for backward compatibility, search should be used now instead.

    If you're isn't working, I'd say double-check the column name. We're happy to take a look if you can provide a live example like mine above.

    Cheers,

    Colin

  • vivalazvivalaz Posts: 7Questions: 4Answers: 0

    I had an array of columns like a:

    { data: 'col1'},
    { data: 'col2'}
    

    I added name property like that:

    { data: 'col1', name: 'col1'},
    { data: 'col2', name; 'col2'}
    

    And its works.
    Special thanks for search note ;)

Sign In or Register to comment.