/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
PrimeFaces.widget.DataTable.prototype.filter = function() {
    var $this = this,
    options = {
        source: this.id,
        update: this.id,
        process: this.id,
        formId: this.cfg.formId,
        params: [{name: this.id + '_filtering', value: true},
                 {name: this.id + '_encodeFeature', value: true}],
        onsuccess: function(responseXML, status, xhr) {
            PrimeFaces.ajax.Response.handle(responseXML, status, xhr, {
                    widget: $this,
                    handle: function(content) {
                        this.updateData(content);

                        if(this.cfg.scrollable) {
                            this.alignScrollBody();
                        }

                        if(this.isCheckboxSelectionEnabled()) {
                            this.updateHeaderCheckbox();
                        }

                        if(this.cfg.stickyHeader) {
                            $this.thead.find('.ui-column-filter').prop('disabled', false);
                            $this.clone = $this.thead.clone(true);
                            $this.cloneContainer.find('thead').remove();
                            $this.cloneContainer.children('table').append($this.clone);
                            $this.thead.find('.ui-column-filter').prop('disabled', true);
                        }
                    }
                });

            return true;
        },
        oncomplete: function(xhr, status, args) {
            var paginator = $this.getPaginator();
            if(paginator) {
                paginator.setTotalRecords(args.totalRecords);
            }
        }
    };

    if(this.hasBehavior('filter')) {
        var filterBehavior = this.cfg.behaviors['filter'];

        filterBehavior.call(this, options);
    } 
    else {
        PrimeFaces.ajax.AjaxRequest(options); 
    }
}
