Skip to content
This repository has been archived by the owner on Feb 2, 2025. It is now read-only.

angular-datatables.columnfilter postRender is called multiple times (breaks the Column Filter plugin) #244

Closed
thesafetylemur opened this issue Mar 12, 2015 · 4 comments

Comments

@thesafetylemur
Copy link

Hi,
This bug can actually be viewed here: http://l-lin.github.io/angular-datatables/#/withColumnFilter
Notice how the input fields are empty and the "all" option in the select list is "Last Name YodaTitiKyleBarWhateveryournameis".
When the postRender function for Column Filter is first called, the input and select fields are added, using the text in the th tags as the "placeholder" text or the first "All" option (respectively). This is fine, but the problem is that postRender is called again, which alters the input and select fields, resulting in empty input fields and the weird looking value for the "All" option in a select list...
My guess is that we'll want to prevent the postRender in the initColumnFilterPlugin function from executing multiple times. A fairly naive approach might be:

function initColumnFilterPlugin(DTRendererService) {
    var columnFilterPlugin = {
        postRender: postRender
    },
    rendered = false;
    DTRendererService.registerPlugin(columnFilterPlugin);
    function postRender(options, result) {
        if (!rendered && options && options.hasColumnFilter) {
            rendered = true;
            result.dataTable.columnFilter(options.columnFilterOptions);
        }
    }
}

This would obviously not help in cases where select lists are used and the options are filled by the values in the table (any new entries in that column wouldn't be rendered). I'm not sure if there's a better way without having to dig into the dataTables.columnFilter code as well...
I'm curious to see what thoughts others may have on this.
Thanks!

l-lin added a commit that referenced this issue Mar 13, 2015
@l-lin
Copy link
Owner

l-lin commented Mar 13, 2015

I inspected the issue. As you noticed, the DataTables is rendered twice, but with a slightly different option.
For some unknown reason, the second time it renders, it adds the attribute bRegex to false for the third column (it must be the plugin columnFilter that adds it). Thus the condition in the watcher returns false and the table is rendered again.

So, I guess we need to provide every attributes for the columnFilter options.

@thesafetylemur
Copy link
Author

Huh, weird. Just tried out, looks like it's working fine for me now. Thanks!

@blop
Copy link

blop commented Apr 9, 2015

I do have the same issue in 0.4.2.
postRender() is called twice.
The filters input fields are empty and i get concats of values in comboboxes.

I think this issue should be reopened.

@blop
Copy link

blop commented Apr 10, 2015

I'm using this workaround (slightly different from the version of thesafetylemur, 1 boolean per dataTable) :

function initColumnFilterPlugin(DTRendererService) {
    var columnFilterPlugin = {
        postRender: postRender
    };
    DTRendererService.registerPlugin(columnFilterPlugin);

    function postRender(options, result) {
        if (options && options.hasColumnFilter) {
            if (result.dataTable.filtersRendered !== true) {
                result.dataTable.filtersRendered = true;
                result.dataTable.columnFilter(options.columnFilterOptions);
            }
        }
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants