Quantcast

sorting dgrid/dstore

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

sorting dgrid/dstore

Simon Walter
Hi all,

I am still working on a solution for this. I have found Ken's words here:
http://stackoverflow.com/questions/26783489/non-case-sensitive-sorting-in-dojo-dgrid

Ken or anyone else, where do I start to do this with dstore? I think
your answer on SO was relevant to dojo/store. What do I extend/override?
What function is called on sort? If there is documentation, forgive me,
I must have missed it.

Simply, I want to override the sorting. It's not working well in 50% of
the cases: integers do not sort correctly, and values from other
database tables (think html select) do not sort correctly.

Thank you,

Simon
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sorting dgrid/dstore

Simon Walter
On 06/08/2016 03:33 PM, Simon Walter wrote:

> Hi all,
>
> I am still working on a solution for this. I have found Ken's words here:
> http://stackoverflow.com/questions/26783489/non-case-sensitive-sorting-in-dojo-dgrid
>
> Ken or anyone else, where do I start to do this with dstore? I think
> your answer on SO was relevant to dojo/store. What do I extend/override?
> What function is called on sort? If there is documentation, forgive me,
> I must have missed it.
>
> Simply, I want to override the sorting. It's not working well in 50% of
> the cases: integers do not sort correctly, and values from other
> database tables (think html select) do not sort correctly.
>

OK, I am starting to figure this out with dgrid. Are 'sort' and 'filter'
the correct functions to override?

So I look in Store.js to get some ideas and I see that both sort and
filter are instances of QueryMethod. Just to get a working model, I copy
the implementation into my own "class" like so:

            var Store = declare([Rest, RequestMemory, Cache, Trackable], {

                 filter: new QueryMethod({
                     type: 'filter',
                     normalizeArguments: function (filter) {
                         var Filter = this.Filter;
                         if (filter instanceof Filter) {
                             return [filter];
                         }
                         return [new Filter(filter)];
                     }
                 }),

                 Filter: Filter,

                 sort: new QueryMethod({
                     type: 'sort',
                     normalizeArguments: function (property, descending) {
                         var sorted;
                         if (typeof property === 'function') {
                             sorted = [ property ];
                         } else {
                             if (property instanceof Array) {
                                 sorted = property.slice();
                             } else if (typeof property === 'object') {
                                 sorted = [].slice.call(arguments);
                             } else {
                                 sorted = [{ property: property,
descending: descending }];
                             }

                             sorted = arrayUtil.map(sorted, function
(sort) {
                                 // copy the sort object to avoid
mutating the original arguments
                                 sort = lang.mixin({}, sort);
                                 sort.descending = !!sort.descending;
                                 return sort;
                             });
                             // wrap in array because sort objects are a
single array argument
                             sorted = [ sorted ];
                         }
                         return sorted;
                     }
                 })
             });


I am guessing this is not correct, because how will this be called. It
works in Store.js, but not in my code.

Do I need to have a function that instantiates the object and then calls
normalizeArguments? How is this called in Store.js and not in my custom
store?

Thanks,

Simon
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sorting dgrid/dstore

Simon Walter


On 06/08/2016 06:07 PM, Simon Walter wrote:

> On 06/08/2016 03:33 PM, Simon Walter wrote:
>> Hi all,
>>
>> I am still working on a solution for this. I have found Ken's words here:
>> http://stackoverflow.com/questions/26783489/non-case-sensitive-sorting-in-dojo-dgrid
>>
>> Ken or anyone else, where do I start to do this with dstore? I think
>> your answer on SO was relevant to dojo/store. What do I extend/override?
>> What function is called on sort? If there is documentation, forgive me,
>> I must have missed it.
>>
>> Simply, I want to override the sorting. It's not working well in 50% of
>> the cases: integers do not sort correctly, and values from other
>> database tables (think html select) do not sort correctly.
>>
>
> OK, I am starting to figure this out with dgrid. Are 'sort' and 'filter'
> the correct functions to override?
>
> So I look in Store.js to get some ideas and I see that both sort and
> filter are instances of QueryMethod. Just to get a working model, I copy
> the implementation into my own "class" like so:
>
...
>
> I am guessing this is not correct, because how will this be called. It
> works in Store.js, but not in my code.
>
> Do I need to have a function that instantiates the object and then calls
> normalizeArguments? How is this called in Store.js and not in my custom
> store?
>


OK, so again, talking to myself hoping some kind soul will laugh at my
ignorance and give me a word or two.

I think I the order of in which the "mixins" are declare() makes a
difference. I am sure it is somewhere in the documentation. I notice Ken
says about dojo/store:

"...one thing to note about SimpleQueryEngine is that if you pass a
function via queryOptions.sort rather than an array, it will be applied
verbatim as the sort function to use."

I see the statement:
if (typeof property === 'function') sorted = [ property ];

Does that mean the same thing will happen with dstore? Can I specify
this function in the store configuration? Like:

var restStore = new Store(
{
     target: restStoreTarget,
     rangeStartParam: 'start',
     rangeCountParam: 'count',
     sortParam: 'sort',
     sortQuery: function (param){} // this here?
});

Thanks for your time,

Simon
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sorting dgrid/dstore

Simon Walter
Sorry everyone,

I realized that mysql drivers were returning everything as strings.
Therefore the JSON was incorrect and there for the sorting and filtering
was incorrect. I will fix that first and see what happens before trying
to write custom sorting and filtering.

Cheers,

Simon
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sorting dgrid/dstore

Simon Walter
On 06/09/2016 06:01 PM, Simon Walter wrote:
> Sorry everyone,
>
> I realized that mysql drivers were returning everything as strings.
> Therefore the JSON was incorrect and there for the sorting and filtering
> was incorrect. I will fix that first and see what happens before trying
> to write custom sorting and filtering.
>

OK! Now with that problem fixed, the numbers are sorting properly.

I think I might still need to write something for sorting these type of
fields:


             {
                 field: 'ServiceID',
                 label: 'Service',
                 editor: Select,
                 editOn: 'click',
                 sortable: true,
                 editorArgs: {
                     style: 'width:75px;',
                     options: selectConfig['selectServiceID']
                 },
                 renderCell: function(object, value, node, options)
                 {
                     return
document.createTextNode(selectConfig['selectServiceIDval'][value]);
                 }
             }

So basically the data in the collection is a number. However, the
renderCell shows the correct value from the foreign table. That is also
used with a select (combobox) cell editor.

Any ideas?

Thanks in advance!

Simon
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Loading...