ng2-table icon indicating copy to clipboard operation
ng2-table copied to clipboard

Default value for filter - filterString

Open eti1boss opened this issue 9 years ago • 3 comments

The property "filterString" seems to be unused. According to the documentation, I thought this property would be used to set the default value of a search field. In this example, I set a value, but I can't find it anywhere.

COLUMNS: [
    { title: 'name', name: 'name', filtering: { filterString: 'MY DEFAULT VALUE', placeholder: 'Filter by name' } },
    { title: 'comments', name: 'comments', filtering: { filterString: '', placeholder: 'Filter by comments' } },
    { title: 'date', name: 'date' },
    { title: 'typeName', name: 'typeName' },
]

image

I found this piece of code, but I don't really understand how it works..

function NgTableFilteringDirective(element, renderer) {
    this.ngTableFiltering = {
        filterString: '',
        columnName: 'name'
    };
    this.tableChanged = new core_1.EventEmitter();
    this.element = element;
    this.renderer = renderer;
    // Set default value for filter
    setProperty(this.renderer, this.element, 'value', this.ngTableFiltering.filterString);
}

And in this code, the input search doesn't contain the "value" property.

<input *ngIf=\"column.filtering\" placeholder=\"{{column.filtering.placeholder}}\"\n [ngTableFiltering]=\"column.filtering\"\n class=\"form-control\"\n style=\"width: auto;\"\n (tableChanged)=\"onChangeTable(config)\"/>\n

Finally, is there a way to define a value to the input or what am I doing wrong ?

eti1boss avatar Nov 23 '16 14:11 eti1boss

Yes i have came across this issue. Although the config has the filterString set the input doesnt show the text in it.

ngmgit avatar Jan 20 '17 07:01 ngmgit

any solution to this one?

jessiejuachon avatar Oct 24 '17 02:10 jessiejuachon

Yes, the ng-table-component.ts class needs to be changes slightly: the input tag for the filter string needs to have this added: value="{{column.filtering.filterString}}". I will try and create a PullRequest for this.

breitling avatar Oct 30 '18 14:10 breitling