[x] bug
Sort and filter should not be tied together.
I shall not need to create a custom filter just to avoid sort.
Why not expose sortable.
Object.defineProperty(ClrDatagridColumn.prototype, "sortBy", {
get: function () {
return this._sortBy;
},
set: function (comparator) {
console.log('setsortBy', comparator, this._field)
if (typeof comparator === "string") {
this._sortBy = new DatagridPropertyComparator(comparator);
}
else {
if (comparator) {
this._sortBy = comparator;
}
else {
if (this._field) {
console.log('!!!!!!! this is an UNNECESARY assumption !!!!!!!!!!!>>>>>>>>>')
this._sortBy = new DatagridPropertyComparator(this._field);
}
else {
delete this._sortBy;
}
}
}
}
_Originally posted by @kathygit in https://github.com/vmware/clarity/issues/831#issuecomment-422522788_
The reason I call this as a BUG is that, the setter is not called when we don't have [clrDgSortBy]="xxx", in which case it is fine to let it sort by the same property as clrDgField.
But if user clearly set it to [clrDgSortBy]="''" or [clrDgSortBy]="null", clr should NOT resort to the default the behavior.
@kathygit have you checked the string-filtering feature? It seems to me that the feature could easily solve your case.
Example: https://stackblitz.com/edit/basic-structure-custom-string-filter?file=src/app/app.component.ts
That is a great utility, but it is not the solution to this issue.
As I mentioned earlier, we shall not tightly couple filter with sort. Often time, we need one, but not the other.
What you consider an "unnecessary assumption" is actually the fix for #846.
We've always decided against extra verbose inputs for individual features, to avoid the datagrid's API being too long to learn. Every time someone asked the same feature you are asking right now, they realized it was actually better UX to let the user sort. Since you say you can use the default filter, that means default sort should work absolutely fine.
Could you please share your use case for having the default filter but not the default sort? Thanks.
Could you explain why the string filter feature is not a solution to the issue? If you need only filtering, I don't see why the method I mentioned above wouldn't work.
If you only need sorting, you can achieve that with enabling only [clrDgSortBy] without [clrDgField]. Example: https://stackblitz.com/edit/basic-structure-sort-only?file=src/app/app.component.html
Maybe you could explain why we want to couple sort with filter ?
any reason why [clrDgSortBy] and [clrDgField] can't work together ?
The string-filtering feature, to me, is a work-around, not a true fix.
I think the default behavior is great, that I need to define [clrDgField]="'name'" only, it will do both sort and filter.
But when I specify the sortby, e.g. [clrDgSortBy]="'age'" or [clrDgSortBy]="null", it should NOT ignore my intended setting.
Secondly, it is not reasonable for the consumer of this component to expect clrDgSortBy works only when there is a custom filter defined, but doesn't work with default filter.
Hi everyone, in my case, I use server-side driven datagrid, and some columns contain information about many objects(5 - 10 in my case, I show all information when row expanded, and just first when not). I would like user can filtering this rows but does not use ordering, since it contains few objects, then not exist common design rules how to sorting that information.
I'm trying to adapt solution of @Shijir with clr-dg-string-filter, but it does not offer access to the property through
refresh(state: ClrDatagridStateInterface) {
for (let filter of state.filters) {
let { property, value } = <{ property: string, value: string }>filter;
}
}
Maybe if clr-dg-string-filter must work with this interface then we must make a bug report. Or if it doesn't then can offer a solution for turning off sorting, but have filtering by text?
Is there any solution to enable and disable sorting on Datagrid Columns with a boolean value yet?
@kathygit Were you able to figure out something?
We still haven't heard of an actual use case for this feature, so I'm going to close this issue. As a reminder, here are the use cases we have identified:
[clrDgField], it's just a property on your objects. In this case, sorting is "free", already implemented, and improves the user experience overall. We do not see a reason to turn sorting off in this case.[clrDgField], either because the type of values means you need a custom filter or because the column isn't tied to a specific property on your objects. In this case, you need to implement a custom filter so turning off sorting is easy, you just give the custom filter to the column and simply do not activate sorting.The comments above haven't shown us any use case outside of these two, but feel free to give us a real-life example if you believe we're wrong.
I, and quite a few others, clearly stated above that we want to be able to filter but NOT sort a column using the handy clrDgField. I wonder why you think it is not a "actual" use case ... We need it often.
What if add an additional feature for disabling ordering as suggest @kathygit . And it must not break already existed functionality.
[clrDgSortBy]="'age'" [clrDgSortBy]="null"
Is that solution have any cons?
What @youdz is saying is that we don't have a use case, a clear situation where sorting is not desired. Just asking for the behavior to change doesn't give us context into what problem you are trying to solve with this request.
@Akay7 It sounds like your case is not related because you are talking about a server driven datagrid which sorting and filtering is handled by your application and not internal to the datagrid.
@gnomeontherun yes, I'm using the server-driven grid. But I just get params for filtering and sorting from grid state. And I would like to use less code for show unorderable columns.
Right now I see just two choices for showing to a user about column not sortable:
I open for any suggestions.
I have a use-case recently discussed with a user on slack:
We have a datagrid where the order of elements is of importance.
We need filtering to be able to find a specific record,
but we don't want to change the order of the records.
This sounds reasonable to me. An even more specific example from my work on the vRO web client was showing log events. The natural order in which these events occur is the only one that you normally care of. In the same time, filtering based on type, severity, keyword is important.
Can the sorting be disabled?
@digish777 I guess it's required to override column.
Hi there 馃憢, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary.
Most helpful comment
I have a use-case recently discussed with a user on slack:
This sounds reasonable to me. An even more specific example from my work on the vRO web client was showing log events. The natural order in which these events occur is the only one that you normally care of. In the same time, filtering based on type, severity, keyword is important.