-
-
Notifications
You must be signed in to change notification settings - Fork 19
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(selectEditors): add select grid editors #22
Conversation
select editors are common with data to ensure data integrity
Could you please modify 1 of the example, possibly Example 3, to include that editor? It would be easier to test it out. EDIT |
added the From the looks of it, I do not think the |
I added the Actually thinking about it while writing, I think the editor goes away while you drag a column since it goes away onBlur, is that right? if so, no need for that |
It looks like the grid commits the change and closes the editor when moving a column while an editor is opened except for the new |
I'm practically done with my PR #23 but I'd like to get this PR here in place before pushing a new release. I have left some comments which we can discuss |
which comments did you want to discuss? Sorry I might have missed some |
see the review comments on top |
sorry I am looking for these "review comments" at the top and can't find them. I am probably looking in the wrong place and they are probably right in front of me somewhere. Once I find where those are I can review those tomorrow. |
|
||
init() { | ||
if (!this.args) { | ||
throw new Error('[Aurelia-SlickGrid] A filter must always have an "init()" ' + |
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.
any particular reason why you've put this on 2 lines?
Are you following the editor max length? I would rather see only 1 line here
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 can change this to one line. I have a max line length of 80 in my editor. Do you have this setting in a file, if so what is it?
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 have this setting and I don't follow it either. I understand it's for readability and I try to split into multiple lines when it's long but it's my own judgement
'{ filter: type: FilterType.multipleSelect, collection: [{ value: true, label: \'True\' }, ' + | ||
'{ value: false, label: \'False\'}] }'); | ||
} | ||
this.optionCollection = this.columnDef.filter.collection || []; |
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.
looking at this, I don't really like seeing a filter
object inside an editor
. I would still rather see params.collection
than filter.collection
. Unless you have good reasons, I would rather change this to be more generic if possible, or put a generic property in the columnDef
. Second note, I previously changed selectOptions
to collection
to be more generic, so the choice of optionCollection
is rather similar, it's probably better than selectOptions
anyhow.
The datalist
actually prove that it was a good decision since selectOptions
doesn't fit in. You could argue that optionCollection
makes more sense and you would probably be right but since I've already changed to collection
in the Filter, we should probably stick with that for now, until version 2.x
(which I will add a note in the 2.x refactoring)
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 can change it to reference params.collection
. That should be no problem.
So do you want me to change the optionCollection
property name in the editor to be named collection
? optionCollection
should be a private property in the editor since it is just a reference to collection
, and to be honest I cannot remember why I called the property optionCollection
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.
What about accessing the customStructure
? I use this in both the editors and the collectionFormatter
? Should that be params.customStructure
too?
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.
And the reason I chose to use the filter
object is because i assumed most of the time the filter.collection
and filter.customStructure
would be the same for the editors collection
and customStructure
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.
To make it to work in both Editor and Filter, we will have to review all the Filters, for example the MultipleFilter should use this instead
-if (!this.columnDef || !this.columnDef.filter || !this.columnDef.filter.collection) {
+if (!this.columnDef || !this.columnDef.filter || !this.columnDef.filter.collection || this.columnDef.params.collection) {
throw new Error(`[Aurelia-SlickGrid] You need to pass a "collection" for the MultipleSelect Filter to work correctly. Also each option should include a value/label pair (or value/labelKey when using Locale). For example:: { filter: type: FilterType.multipleSelect, collection: [{ value: true, label: 'True' }, { value: false, label: 'False'}] }`);
}
-const optionCollection = this.columnDef.filter.collection || [];
+const optionCollection = this.columnDef.filter.collection || this.columnDef.params.collection || [];
You can keep the optionCollection
within the editor if you want but the one in the interface should really be collection
to align with the already implemented Filters. As mentioned in my previous post, we can revisit that in 2.x
I didn't think about the customStructure
but yeah it also makes sense to put it in the params
as well. I understand the filter
principle but still I would rather make a perfect cut between the 2 and not see anything about filter
within an editor
, it might confuse some users to do that, however params
is generic enough not to confuse them.
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.
do you want me to ignore the filterOptions that I was creating and pass no options? Or should there be a property on the params
object?
- const filterOptions = (this.columnDef.filter) ? this.columnDef.filter.filterOptions : {};
- const options: MultipleSelectOption = { ...this.defaultOptions, ...filterOptions };
- his.$filterElm = this.$filterElm.multipleSelect(options);
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.
oh I guess that would be another thing that we can put inside the params
and make the Editor and Filter share it, when provided. We can update the Filter in a separate PR as you suggested, but for Editor, it would be
+ const selectOptions = (this.columnDef.filter) ? this.columnDef.params.options : {};
+ const options: MultipleSelectOption = { ...this.defaultOptions, ...selectOptions };
+ his.$filterElm = this.$filterElm.multipleSelect(options);
not sure about options
though, it might be too generic. How about domOptions
or elementOptions
?
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 can see elementOptions
because it is for the actual dom element, but do we need to specify it is for the collection element? collectionOptions
?
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 think it's more for the multiple-select
DOM element, so I would go more with elementOptions
or domElementOptions
but it's prob too long
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 can go with elementOptions
. The only downside I can see with this approach is if there were ever other elements in the column, then they would potentially have to share this elementOptions
, but this might be how you want it designed since most DOM elements wont share many properties.
It will be a bit before I update this PR, but I will have it to you later this evening.
type: FieldType.string, | ||
editor: Editors.multipleSelect, | ||
filter: { | ||
collection: Array.from(Array(1001).keys()).map(k => ({ value: `Task ${k}`, label: `Task ${k}` })) |
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.
goes with the other comment, I would rather see params.collection
instead of seeing filter.collection
to be used in both multiSelect
.
oh gosh I feel embarrassed, I thought it was live review, I didn't know that I had to send the review once it's completed. feel dump oopsy |
I'll try to get in the revisions at some point today or later tonight. I will not be in the office today and I will have limited access to my computer. |
Sure whenever is best for you, no rush. However if you can't make it by tomorrow, then let me know and I'll cut a release tonight instead. Thanks |
also make error message and editor property names more meaningful
Okay I think I changed everything, but let me know if I missed something. I will be unavailable for the next few hours. |
One more thing I'll need your opinion on that i just realized. The editors assume that the data item is a foreign key reference and not a complex object with a Is this a bad assumption and should I support a list of values and a list of complex objects with a |
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.
1 very small missing curly brace, the rest looks good. I will give it a try later after work and cut a release tonight then. Thanks
'Locale) is required to populate the Select list, for example:: { filter: ' + | ||
'type: FilterType.multipleSelect, collection: [ { value: \'1\', label: \'One\' } ])'); | ||
'Locale) is required to populate the Select list, for example: ' + | ||
'{ collection: [ { value: \'1\', label: \'One\' } ])'); |
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.
You added an open curly brace in your throw error, though I think it's missing an ending curly brace.
container: 'body', | ||
filter: false, | ||
maxHeight: 200, | ||
width: '100%', |
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.
you should not fix this to 100%, it makes the option "autoDropWidth" unusable. The "autoDropWidth" is a new option that I added which will resize the drop menu with the same size as the input select element.
Now that I am testing it locally, here are some observations
this.$editorElm = this.$editorElm.multipleSelect(options);
+ setTimeout(() => {
+ this.$editorElm.multipleSelect('open');
+ }, 0); Before (no options passed, use the defaults that include |
Thank you for the feedback. I will look this over and answer your questions a bit later when I am near my computer. Not sure how late I am able to work tonight so you can cut a release without this if you like. |
I can wait another day, no hurry. |
If you are not opposed, lets keep
I think this might be a larger issue because we do not have control over creating an editor to inject the |
Yes sure, we can always create more PR. I am not opposed to that at all, I always prefer to ask :) You can also use Also feel free to add some info on things you would like to correct in version |
Since I have that in mind, I wanted to tell you yesterday that the dateEditor does use the |
also create an exact width so it plays nice with the multipl-select library
Okay let's see if i fixed all your notes:
|
|
||
constructor(private args: any) { | ||
this._i18n = this.args.column.params.i18n; |
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.
this will probably fail at Build, args
could possibly be undefined here
|
||
constructor(private args: any) { | ||
this._i18n = this.args.column.params.i18n; |
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.
same as before.. this will probably fail at Build, args
could possibly be undefined here
Awesome this looks really nice, I tried it over lunch and yes you did addressed all the things I said. BTW, the offset is only required on the last column, in the middle it's not really needed. |
I ran the build and I did not receive any errors. Did you see errors on your end? For the offset, should I have to somehow dynamically set that value if it is the last column or always setting that value the way I did it won't hurt anything? |
I didn't see any errors, I assumed the Build would throw an error. If it's ok then fine |
This pull request brings two new editors and one small change and should close #18
Purpose
Select editors are very common with data to ensure data integrity and we already provide these are header filters.
Features
SelectListFilter
. If the developer does not usemultiple-select
library, this editor falls back to a bootstrapform-control
. For this to render property in the grid a new css rules was added.MultipleSelectListFilter
. If the developer does not usemultiple-select
library, this editor falls back to a bootstrapform-control
label
value in thefilter.collection
based on the value passed into the formatter. If it is an array, it will use thearrayToCsvFormatter
MultipleSelectListEditor
find
returns undefined the consumer of this function can still safely try and access the property since by default the returned value is an empty object.Changes
Tests
I didn't start creating unit tests yet because
aurelia-pal-nodejs
needs to be updated because of this fix aurelia/pal-nodejs#24 and another error i need to research about imports. Therefore, I manually tested with example 3 by changing the editor on the effort-driven column and adding/removing the multiple-select lib.Comments
this.labelName = (this.columnDef.filter.customStructure) ? this.columnDef.filter.customStructure.label : 'label';
since it is referenced in 3 files now. We could have a defaultcolumnDef.filter
object that ensures thecustomStructure
is always there.Filter
andEditor
or just wait to see if we can/want to suppose templates