Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.
This repository was 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

@thesafetylemur

Description

@thesafetylemur

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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions