How can I enable grid sorting with nested object. For example I have the following object which I bind locally to the grid
{
DataId: 1,
Duration: 4.5,
Customer: {
CustomerId: 1,
Name: 'Foo'
}
}
Now I want to enable sorting for the Name of the Customer (Customer.Name). The parse method didn't worked for me, cause I wrote a custom editortemplate which replace the complete customer with the new selected one.
Related
I'm trying to create graphics with the libraries crossfilter, d3 and dc, and it works well until I create the dimension with an array of objects like this:
{ age: 12, name: 'John Doe', ocupation: 'developer' }
But when in the data I use nested objects and create dimentions with them it wont works to me.
Nested object example:
{ age: 12, name: 'John Doe', nested: { value: 'developer' } }
I don't find any docs about how to use crossfilter with nested objects, then is it possible?
How can I do it?
You define the accessor functions for crossfilter, so you can define them however you like.
For example, if you're trying to create an occupation dimension, you could do
var occDimension = cf.dimension(function(row) {
return row.nested.value;
})
If this was not your question, you'll need to provide more details and an example of the code which didn't work.
Is possible to remove or add aggregations to parent control.
For example:
sap.ui.define([
"sap/m/StandardListItem"
], function(StandardListItem) {
return StandardListItem.extend("my.controls.CustomListItem", {
metadata: {
properties: {
"name": 'string'
},
aggregations: {
"nameIcon": {
type: "sap.ui.core.Icon",
multiple: false,
visibility: "hidden"
},
Is possible to remove some element from parent(StandardListItem) or add nameIcon btw elements from StandardListItem ?
You cannot remove properties, associations, aggregations and events inherited from the base class. The baseclass aleady parsed its metadata and generated the accessors, fields etc in its prototype. Your class does the same and adds everything you define in the metadata to its prototype.
You can however overwrite the asccessors (getXxx, setXxx, addYyy, removeYyy, attachZzz,...) of the baseclass and do nothing or throw an exception inside.
But you can add as many properties, associations, aggregations and events as you like. Just declare them in your metadata as you have done in your example.
I have table bound to set of elements with nested value. I made custom editor for this element which is kendoDropDownList. It loads dictionary values from server. It works fine, when i edit values, but when i create new element, dropdown inserts Id value (data-value-field="Id").
So i recieve that:
{
"Id":"",
"DateFrom":"2013-12-06 15:43:39Z",
"DateTo":"2013-12-06 15:43:39Z",
"Person":"3e31b740-7ced-4232-8cfc-cb3e100e372f"
}
but i need
{
"Id":"",
"DateFrom":"2010-10-09 23:00:00Z",
"DateTo":"2011-11-10 23:00:00Z",
"Person": {
"Id":"eeb97990-d191-4508-93c1-55f9ca3681d5"
}
}
I found solution! I defined defaultValue for my nested entity in schema of my table's datasource, it works for me.
In my Ext JS 4.1 application, I have a model Project with an belongsTo association to ProjectCategory:
Ext.define('MyApp.model.Project', {
extend: 'Ext.data.Model',
fields: ['id', 'project_category_id', 'title'],
belongsTo: {
model: 'MyApp.model.ProjectCategory',
associationKey: 'ProjectCategory',
getterName: 'getCategory'
}
// ...
});
Ext.define('MyApp.model.ProjectCategory', {
extend: 'Ext.data.Model',
fields: ['id', 'title']
});
The project is read via a Direct proxy, and ProjectCategory details are included as nested values in the response (mostly for display purposes). When loading a store, the associated data is read correctly, and I'm able to read the ProjectCategory's title in a grid via a custom renderer:
renderer: function(v, p, rec) {
return v ? rec.getCategory().get('title') : '';
}
However, when editing and saving the parent Project record through form.updateRecord(record), the associated record's fields aren't updated with values from the server response, unlike the Project's "native" fields. So when changing the project_category_id, even though the server will respond with a correctly nested ProjectCategory field containing the new category, getCategory will still return the old category.
Why isn't this updated from the server response, and what do I have to do to update it?
I already found out that in the store's write listener, I have access to the record and the returned association data. But I can't figure out how to update the record silently without triggering any other events.
It seems like I found my solution. Add this to the Project store:
listeners: {
write: function(store, operation, opt) {
var c = operation.records[0].getCategory();
c.set(operation.response.result.ProjectCategory);
c.commit(true);
}
}
The key element is the commit(true) call, which will skip notifying the store/proxy about the changes.
It's still a bummer that this isn't done automatically, though.
I have a store + model which is connected to a 3rd party plugin (Ext.ux.TouchGridPanel). The plugin calls the store's sort() method properly with the relevant mapping. Everything is working fine, and the store sorts itself. However, I would prefer to add customer sorting to the store. I have tried adding a sortType field into my model:
Ext.regModel("Transactions", {
fields: [
{
name: 'unit',
type: 'string',
sortType: function(value) {
console.log('PRINT GDAMNIT');
return 0;
}
},
...
]
});
This, however, is not working, and the sortType is not getting called.
TLDR: How to make custom sorting work for stores?
Your store will need a sorter added that will sort on that field before it will call the sortType function.
var store = new Ext.data.Store({
model: 'Transactions',
sorters: [
{
property: 'unit',
direction: 'DESC'
}
]}
);
Sort type converts the value of a field into another value to ensure proper ordering. If you aren't sorting on that field than there is no reason to call that function. You could add the sortDir to the field which would sort the field into ascending/descending order based on the type of the field alone.
A workaround might be to (I know this sounds inefficient but bear with me) add an extra field to your model instances (lets call it sortField) and use that for your sorting function. You can then loop through your model instances in your store applying your custom sorting algorithm and assign a sort value of 0,1,2,3,4,5 etc.. to sortField. Then in your store, you can add 'sorters: 'sortField'... Hope this helps a bit, I'm going through something similar at the current moment.
The custom SortType in Sencha Touch 2 works accordingly, as per http://docs.sencha.com/touch/2-0/#!/api/Ext.data.SortTypes:
Ext.apply(Ext.data.SortTypes, {
asPerson: function(person){
// expects an object with a first and last name property
return person.lastName.toUpperCase() + person.firstName.toLowerCase();
}
});
Ext.define('Employee', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'person',
sortType: 'asPerson'
}, {
name: 'salary',
type: 'float' // sortType set to asFloat
}]
}
});
What you're attempting to do might be tricky. Calling store.sort() removes all existing sorters by default (according to Sencha Touch API documentation). To keep the existing sorters you would need to add the sorter to the MixedCollection store.sorters.
Secondly, to call the sort method with a custom sort function, you would need to pass a specific sorterFn instead of property to the Sorter (again, see the API for more details) - but this might prove tricky since the sort call is initiated from the plugin.
Not sure if this helps to solve your problem, but maybe it assists you to look at the right direction.