chifailai2 / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

type: select filters should handle simple objects as well #61

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Here are the cases how a select can be generated:

1, simple array - value = label:
"type":"select","values":{"Y","N"}
The values and the labels of the option tag will be Y,N

2, associative array (object), with value parametzer of associative arrays - 
value != label
"type":"select","values":[{"value":"Y","label":"Yes"},{"value":"N","label":"No"}
]
The value will be the value and the label will be the label, but it a little 
bit ugly

3. NEW sorthand method for type 2 (value != label)
"type":"select","values":{"Y":"Igen","N":"Nem"}
The value will be the value and the label will be the label

here is the code to be put in fnCreateColumnSelect

Change from:
            var r = '<select class="search_init select_filter"><option value="" class="search_init">' + sLabel + '</option>';
            var j = 0;
            var iLen = aData.length;

TO:

            var r = '<select class="search_init select_filter"><option value="" class="search_init">' + sLabel + '</option>';

            // Handles objects with key as value, and value as label
            if ($.type(aData) == "object"){
                var tmp = aData, tmpValue;
                aData = [];
                for (tmpValue in tmp){
                    aData.push({
                        "value": tmpValue,
                        "label": tmp[tmpValue]
                    });
                }
            }
            var j = 0;
            var iLen = aData.length;

Original issue reported on code.google.com by pi...@pilou.hu on 23 Mar 2012 at 2:59