-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(odata): add case insensitive option for OData search filter #761
feat(odata): add case insensitive option for OData search filter #761
Conversation
@@ -345,6 +345,9 @@ export interface GridOption { | |||
/** Do we want to enable pagination? Currently only works with a Backend Service API */ | |||
enablePagination?: boolean; | |||
|
|||
/** Odata case insensitive search */ | |||
caseInsensitiveOdataSearch?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather have you move the flag to the OData options, in the OdataOption
interface since this is not a common grid option but rather an OData only option, the interface this should belong to is the one shown below
and since that interface is related to OData, we can rename the flag to simply be caseInsensitive
@@ -428,7 +428,16 @@ export class GridOdataService implements BackendService { | |||
} else if (operator === OperatorType.rangeExclusive || operator === OperatorType.rangeInclusive) { | |||
// example:: (Name >= 'Bob' and Name <= 'Jane') | |||
searchBy = this.filterBySearchTermRange(fieldName, operator, searchTerms); | |||
} else if ((operator === '' || operator === OperatorType.contains || operator === OperatorType.notContains) && | |||
} else if (this._gridOptions && (this._gridOptions.caseInsensitiveOdataSearch || !this._gridOptions.hasOwnProperty('caseInsensitiveOdataSearch'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it necessary to add the flag check in the if
condition, I would rather see it in a simpler way, something along the code shown below (untested)
+ if (this.options.caseInsensitive) {
+ searchBy = odataVersion >= 4 ? `contains(tolower(${fieldName}, ${searchValue}))` : `substringof(tolower(${searchValue}, ${fieldName}))`;
+ else {
searchBy = odataVersion >= 4 ? `contains(${fieldName}, ${searchValue})` : `substringof(${searchValue}, ${fieldName})`;
+ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it also looks like the linter failed as well, make sure to have the correct indentation in your code. I use the Editorconfig VSCode extension and also auto-format on save when I run the project. We also need unit tests to cover the change, if you need help let me know, here's 1 of the test for substringof
, I would expect to see at least 2 new unit tests covering your change for both contains(tolower(...))
and ``substringof(tolower(...))`
slickgrid-universal/packages/odata/src/services/__tests__/grid-odata.service.spec.ts
Lines 1057 to 1071 in 9826623
it('should return a query to filter a search value between an exclusive range of dates using 2 search terms and the "RangeExclusive" operator', () => { | |
const expectation = `$top=10&$filter=(substringof('abc', Company) and (UpdatedDate gt DateTime'2001-01-20T00:00:00Z' and UpdatedDate lt DateTime'2001-02-28T00:00:00Z'))`; | |
const mockColumnCompany = { id: 'company', field: 'company' } as Column; | |
const mockColumnUpdated = { id: 'updatedDate', field: 'updatedDate', type: FieldType.date } as Column; | |
const mockColumnFilters = { | |
company: { columnId: 'company', columnDef: mockColumnCompany, searchTerms: ['abc'], operator: 'Contains', type: FieldType.string }, | |
updatedDate: { columnId: 'updatedDate', columnDef: mockColumnUpdated, searchTerms: ['2001-01-20', '2001-02-28'], operator: 'RangeExclusive', type: FieldType.dateIso }, | |
} as ColumnFilters; | |
service.init(serviceOptions, paginationOptions, gridStub); | |
service.updateFilters(mockColumnFilters, false); | |
const query = service.buildQuery(); | |
expect(query).toBe(expectation); | |
}); |
it would be nice to get comments/reviews from @jr01, if possible, since he contributed some nice features in the past. |
Our oData API (backed by SQL server) returns the same data for Usually case-insensitiveness is handled by the server. E.g., if using a SQL database you usually set case insensitive collation at the database level and (if you really have to) make exceptions at column level. In my business domain my users always want to search case insensitive and I have never encountered an exception. A nice read: https://learn.microsoft.com/en-us/ef/core/miscellaneous/collations-and-case-sensitivity So I wonder what the real use case is and if this PR is really needed. @suvirbhargav can you elaborate? |
@jr01 thanks for your reply. I will read it your link..yes, i have the oData, .net 4.7 and sql..no idea why my backend does not work with case insensitiveness. I will read a bit and update here. |
@suvirbhargav
My answer to this in SO was: "you can get that via the Grid State" @jr01 thanks for the comments and feedback, it's really helpful since I haven't used OData in a while 😉 Also a note for everyone, I'm currently working in the next |
Yes, I have been reading the backend code this morning. I think @jr01 has done some needed changes in database at column level to make it case insensitive in response because this works for me |
By the way, as a side note: You both are awesome and thanks a ton to support such a nice library. |
I just released Slickgrid-Universal v2.0.0 and also the external Angular & Aurelia-Slickgrid v5.0.0 Also I don't think this PR is required anymore so I decided to just close it. If you feel that it is still necessary for you, then feel free to reopen but you'll have to add unit tests, I praise on the fact that all my slickgrid libs have 100% unit tested code coverage and that took quite a lot of time and effort, so if you create a new PR, make sure to have unit tests 😉 Cheers |
From SO question, here is some changes for making odata search