getting information about a hidden column

getting information about a hidden column

rolfsfrolfsf Posts: 27Questions: 6Answers: 0

I've got a dataTable, built from a json file, with a hidden 6th column that I use for filtering by category (a category which doesn't appear in the table)

in my aoColumnDefs it looks like so:

    }, {
        "aTargets": [5],
        "mData": 8,
        "bVisible": false
    }

I want to query the table somehow to find out how many records of each category are currently shown in the table (there are various other filters that may be applied at any time).

I thought I might be able to use the $ api to get at the column... something like myTable.$('tr td:eq(5)).text(), but I realize that column doesn't actually appear in the markup.

Is there a built in method that I can get that kind of info out of the table? DataTables obviously has this data because I can filter with it, I just don't know how to get at it. I'm not much of a programmer, so it may be obvious and I'm just overlooking it.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • rolfsfrolfsf Posts: 27Questions: 6Answers: 0
    edited May 2014

    Tinkering away, I'm getting close, I think...

        function countTerm(term){
            var count = 0;
            $( myTable.fnGetNodes() ).each(function(){
                var aData = myTable.fnGetData(this); 
                if(aData[8] === term){
                    count = count + 1;
                }
            });
            return count;
        }
    

    This gives me the correct count of a particular Category (term) in the full dataset, but it doesn't reflect the current filtered table dataset.

    So how do I get the filtered data?

  • rolfsfrolfsf Posts: 27Questions: 6Answers: 0

    solved it this way:

        function countTerm(term){
            var count = 0;
            var data = myTable._('tr', {"filter": "applied"});
            
            $(data).each(function(){
                if(this[8] === term){
                    count = count + 1;
                }
            });
    
            return count;
        }
    

    if there is a better way (for version 1.9), please let me know.
    Otherwise, I hope this answer helps someone else!

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    Looks like a good way in 1.9. In 1.10 you'd simply use table.column(5).data().unique().length :-).

    Allan

  • rolfsfrolfsf Posts: 27Questions: 6Answers: 0

    1.10 is looking pretty sweet, Allan - will try to upgrade soon.

    One follow on question - does 1.9 store a reference to currently applied filters that I can access?

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Not publicly not. It does internally, but there is no public interface for that information in 1.9. 1.10 however, does using column().search().

    Allan

This discussion has been closed.