tochoromero / aurelia-table

Simple functional data table for Aurelia
https://tochoromero.github.com/aurelia-table
MIT License
67 stars 25 forks source link

Filter with null value in cell can't be reset #34

Open Robbe64 opened 7 years ago

Robbe64 commented 7 years ago

Not sure if this is an issue of aurelia-talbe:

I have a filter for a column with some null values. I'm able to init the filter with null to see all entries but after I typed something in the filter input and removed it again the filter is set to an empty string. This results in not showing all rows having null in this column.

daniele-j2ee commented 6 years ago

@Robbe64 Yes, I think it's an issue, I faced out the same error.

When you init the filter value to null, au-table doesn't filter the row, so you will see all the entries. And every time you programmatically reset the filter value to null, you will see all the entries.

But when you bind a filter value to an html input value, things go in a different way, because Aurelia.io framework accepts to change a model value to an empty string '' from null in the case that a user enters a value and then subsequently backs out that value.

This behaviour is explained in the Aurelia.io framework issue #288 and #308, and they suggest to use a NullToEmptyStringValueConverter.

I report here the cause from issue #288:

The primary issue is the input element's value property only stores strings. The element converts null/undefined to empty string.

and from issue #308:

This behaviour is caused by html elements not supporting null values, the value is altered to empty-string. Aurelia supports this in its binding processing. When changing a model property from "some text" to null, this triggers:

1: Aurelia binding ValueAttributeObserver coerces null newValue to empty-string 2: Value detects element.value not equal newValue, so updates the element with newValue and calls notify 3: Notify calls element value subscribers with coerced empty-string 4: The Binding subscriber compares newValue empty-string with evaluated source expression which is still null ... 5: and so updates source model with newValue empty-string.

Seeing the source, I think the AureliaTableCustomAttribute.prototype.passFilter() function should NOT filter rows when filter value is an empty string.