jquery DataTables. How to get filtered (visible) rows

后端 未结 7 1354
盖世英雄少女心
盖世英雄少女心 2021-02-07 02:28

I have a button that apply filter to jquery datatable

$(\"#buttonFilter\").button().click(function() {
                if (lboxColor.val() != null) {
                    


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 03:05

    For those struggling to get data from only one column AND only from visible rows: you can actually combine the "selectors" like this

    var total = api
          .column(2, { search: 'applied' }) // <-- only 3rd column && only visible after applied search
          .data()
          .reduce(function (a, b) {
            return floatVal(a) + floatVal(b)
          }, 0)
    

    I also notices several sources stating { page: 'current' } would be the right selector for currently visible rows, but this one actually gives you the rows visible after a possible pagination.

提交回复
热议问题