i have a model like this
[ {"name":"Main 1","description":"main1 Description",
"children": [{
"name": "SUB 1",
"description": "SUB 1 Description",
"children":[
{
"name": "SUB 1.1",
"description": "SUB 1.1 Description"
},
{
"name": "SUB 1.2",
"description": "SUB 1.2 Description"
} ]
}],
"parent":[{"name": "parent sub"}]
},
{"name":"Main 2","description":"main2 Description",children:[],parent:[]},
{"name":"Main 3","description":"main3 Description",children:[],parent:[]},
{"name":"Main 4","description":"main4 Description",children:[],parent:[]}
]
and i want to display name and description property. The contents in the "children" property should be a sub-level in the row, and i don't want to display "parent" content in this tree table. how can i restrict "parent" property from the tree table.
The sap.ui.model.ClientTreeBinding used by the TreeTable with a JSONModel or XMLModel supports the parameter arrayNames.
This parameter expects an array of the model property names that will create a sublevel (if containing an object).
So in your example you should use something like this:
treeTable.bindRows({path: '/pathToData', parameters: { arrayNames: ['children'] }});
or in XMLView:
<TreeTable rows="{path: '/pathToData', parameters: { arrayNames: ['children'] } }" >
...
</TreeTable>
Theres not much to find in the documentation about this except for one example. You can find the source for the example in the openui5 github.
Try This Should Work
var oData={
"children":[
{"name":"Main 1","description":"main1 Description", "children": [], "parent":[]},
{"name":"Main 2","description":"main2 Description","children":[],parent:[]},
{"name":"Main 3","description":"main3 Description","children":[],parent:[]},
{"name":"Main 4","description":"main4 Description","children":[],parent:[]}
]
};
var oTable = new sap.ui.table.TreeTable({
columns: [
new sap.ui.table.Column({label: "Name", template: "name"}),
new sap.ui.table.Column({label: "Description", template: "description"})
],
selectionMode: sap.ui.table.SelectionMode.Single,
enableColumnReordering: true,
expandFirstLevel: true,
});
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
oTable.setModel(oModel);
oTable.bindRows("/children");
Related
I have a model called category which can have multiple sub categories and belongs to one category, so, it's a auto related model. So I inserted a few in my database (I am using MongoDB) and I want to retrieve all my categories that doesn't belong to any one and include all it's sub categories, so the url is:
http://localhost:300/api/categories?filter={"where": {"category": {"exists": false}}, "include": [{"categories": ["categories"]}]}
And what should return is this:
[
{
_id: 1,
nome: "Elétrica",
categories: [
{
_id: 2,
nome: "Tomada",
categories: [
{
_id: 3,
nome: "Trocar Tomada"
},
{
_id: 4,
nome: "Tomada em Curto Circuito"
},
{
_id: 5,
nome: "Outros"
}
]
}
]
}
]
But it's returning this:
[
{
"nome": "Elétrica",
"id": "5b7c6e2dcaaa163984a6ee76",
"categorias": []
}
]
And in my model.json, the relation is set like this:
"relations": {
"categories": {
"type": "hasMany",
"model": "category",
"foreignKey": "category"
},
"category": {
"type": "belongsTo",
"model": "category",
"foreignKey": "category"
}
}
One thing to mention, is that if I try the inverse query, so query all my categories which belongs to other category and include that category, it works.
Maybe this isn't a loopback issue or my url it's wrong, maybe the problem is that I actually have to store all the sub categories in the top category on Mongo, but I am not sure about that, so if anyone can help me if this..
I managed to get to work by deleting the belongsTo relation in my model.
In treeTable, I don't want to show the data after 3rd node i.e. connList data in first column (in tree). I can't remove node from JSON as I have to use it for another column. Is it possible without removing connList node from json. Please suggest me solution if any. Thanks in Avance!
createContent : function(oController) {
Sample JSON with connList node -
var response={"name": "Root", "checked": "Checked",
"dataList": [
{"name": "Parent1",
"exList": [
{"name": "SubParent1",
"sysList": [{"name": "Child1", "externalId": "External 1",
"connList": [ {"id":1, "name": "conn1" },
{"id":2, "name": "conn2" },
{"id":3, "name": "conn3"}
]
},
{"name": "Child2", "externalId": "External 2" }
]
}
]
},
{"name": "Parent2",
"exList": [
{"name": "SubParent2",
"sysList": [{ "name": "Child3", "externalId": "External 3" },
{ "name": "Child4", "externalId": "External 4" }
]
}
]
}
]
};
TreeTable goes here -
var inputListBox = new sap.ui.commons.ListBox();
inputListBox.bindAggregation("items","connList",function(oId,oContext){
return new sap.ui.core.ListItem({
key: oContext.getProperty("id"),
text: oContext.getProperty("name")
});
});
var oTable = new sap.ui.table.TreeTable("treeTable",{
columns: [
new sap.ui.table.Column({label: "Tree column", template:new sap.ui.commons.TriStateCheckBox({
text: '{name}',
selectionState: '{checked}'
})}),
new sap.ui.table.Column({label: "Child Column", template: "externalId"}),
new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Connection", design:sap.ui.commons.LabelDesign.Bold}),
template: new sap.ui.commons.DropdownBox({
"association:listBox" : inputListBox
})
})
],
selectionMode : sap.ui.table.SelectionMode.Multi,
enableColumnReordering : true,
expandFirstLevel : true
});
var mappingModel = new sap.ui.model.json.JSONModel({listData:response});
sap.ui.getCore().setModel(mappingModel, "mappingModel");
oTable.setModel(mappingModel);
oTable.bindRows("/listData/dataList");
mappingModel.refresh(true);
return oTable;
}
You can define the properties that will be expanded to a new tree level as binding parameter:
oTable.bindRows({path: "/listData/dataList", parameters: {arrayNames: ["dataList","exList","sysList" ]} });
Theres not much to find in the documentation about this except for one example. You can find the source for the example in the openui5 github.
I have some documents in the "company" collection structured this way :
[
{
"company_name": "Company 1",
"contacts": {
"main": {
"email": "main#company1.com",
"name": "Mainuser"
},
"store1": {
"email": "store1#company1.com",
"name": "Store1 user"
},
"store2": {
"email": "store2#company1.com",
"name": "Store2 user"
}
}
},
{
"company_name": "Company 2",
"contacts": {
"main": {
"email": "main#company2.com",
"name": "Mainuser"
},
"store1": {
"email": "store1#company2.com",
"name": "Store1 user"
},
"store2": {
"email": "store2#company2.com",
"name": "Store2 user"
}
}
}
]
I'm trying to retrieve the doc that have store1#company2.com as a contact but cannot find how to query a specific value of a specific propertie of an "indexed" list of objects.
My feeling is that the contacts lists should not not be indexed resulting in the following structure :
{
"company_name": "Company 1",
"contacts": [
{
"email": "main#company1.com",
"name": "Mainuser",
"label": "main"
},
{
"email": "store1#company1.com",
"name": "Store1 user",
"label": "store1"
},
{
"email": "store2#company1.com",
"name": "Store2 user",
"label": "store2"
}
]
}
This way I can retrieve matching documents through the following request :
db.company.find({"contacts.email":"main#company1.com"})
But is there anyway to do a similar request on document using the previous structure ?
Thanks a lot for your answers!
P.S. : same question for documents structured this way :
{
"company_name": "Company 1",
"contacts": {
"0": {
"email": "main#company1.com",
"name": "Mainuser"
},
"4": {
"email": "store1#company1.com",
"name": "Store1 user"
},
"1": {
"email": "store2#company1.com",
"name": "Store2 user"
}
}
}
Short answer: yes, they can be queried but it's probably not what you want and it's not going to be really efficient.
The document structure in the first and third block is basically the same - you have an embedded document. The only difference between are the name of the keys in the contacts object.
To query document with that kind of structure you will have to do a query like this:
db.company.find({ $or : [
{"contacts.main.email":"main#company1.com"},
{"contacts.store1.email":"main#company1.com"},
{"contacts.store2.email":"main#company1.com"}
]});
This query will not be efficient, especially if you have a lot of keys in the contacts object. Also, creating a query will be unnecessarily difficult and error prone.
The second document structure, with an array of embedded objects, is optimal. You can create a multikey index on the contacts array which will make your query faster. The bonus is that you can use a short and simple query.
I think the easiest is really to shape your document using the structure describe in your 2nd example : (I have not fixed the JSON)
{
"company_name": "Company 1",
"contacts":{[
{"email":"main#company1.com","name":"Mainuser", "label": "main", ...}
{"email":"store1#company1.com","name":"Store1 user", "label": "store1",...}
{"email":"store2#company1.com","name":"Store2 user", "label": "store2",...}
]}
}
like that you can easily query on email independently of the "label".
So if you really want to use the other structure, (but you need to fix the JSON too) you will have to write more complex code/aggregation pipeline, since we do not know the name and number of attributes when querying the system. Theses structures are also probably hard to use by the developers independently of MongoDB queries.
Since it was not clear let me show what I have in mind
db.company.save(
{
"company_name": "Company 1",
"contacts":[
{"email":"main#company1.com","name":"Mainuser", "label": "main"},
{"email":"store1#company1.com","name":"Store1 user", "label": "store1"},
{"email":"store2#company1.com","name":"Store2 user", "label": "store2"}
]
}
);
db.company.save(
{
"company_name": "Company 2",
"contacts":[
{"email":"main#company2.com","name":"Mainuser", "label": "main"},
{"email":"store1#company2.com","name":"Store1 user", "label": "store1"},
{"email":"store2#company2.com","name":"Store2 user", "label": "store2"}
]
}
);
db.company.ensureIndex( { "contacts.email" : 1 } );
db.company.find( { "contacts.email" : "store1#company2.com" } );
This allows you to store many emails, and query with an index.
Hopefully someone can help me with this - I've been staring at this for 8 hours and can't seem to find a solution. I'm trying to implement a pretty simple Kendo UI MVVM grid. The grid just has a list of roles with an attached category. When you click edit, the grid should allow an inline edit and the category column should turn into a drop down - which is a template that is also bound to a field in the view model.
Here's my jsfiddle: http://jsfiddle.net/Icestorm0141/AT4XT/3/
The markup:
<script type="text/x-kendo-template" id="someTemplate">
<select class="form-control categories" data-auto-bind="false" data-value-field="CategoryId" data-text-field="Description" data-bind="source: categories"></select>
</script>
<div class="manage-roles">
<div data-role="grid"
data-scrollable="true"
data-editable="inline"
data-columns='[
{ "field" : "JobTitle", "width": 120, "title" : "Job Title Code" },
{ "field" : "Description" },
{ "field" : "Category", "template": "${Category}","editor" :kendo.template($("#someTemplate").html()) },
{"command": "edit"}]'
data-bind="source: roles"
style="height: 500px">
</div>
</div>
And the javascript:
var roleViewModel = kendo.observable({
categories: new kendo.data.DataSource({
data: [
{ "CategoryId": 1, "Description": "IT" },
{ "CategoryId": 2, "Description": "Billing" },
{ "CategoryId": 3, "Description": "HR" },
{ "CategoryId": 4, "Description": "Sales" },
{ "CategoryId": 5, "Description": "Field" },
{ "CategoryId": 10, "Description": "Stuff" },
{ "CategoryId": 11, "Description": "Unassigned" }
]
}),
roles: new kendo.data.DataSource({
data: [
{ "RoleId": 1, "JobTitle": "AADM1", "Description": "Administrative Assistant I", "Category": "Stuff", "CategoryId": 10 },
{ "RoleId": 2, "JobTitle": "AADM2", "Description": "Administrative Assistant II", "Category": null, "CategoryId": 0 },
{ "RoleId": 3, "JobTitle": "ACCIN", "Description": "Accounting Intern", "Category": null, "CategoryId": 0 },
{ "RoleId": 4, "JobTitle": "ACCSU", "Description": "Accounting Supervisor", "Category": null, "CategoryId": 0 }, { "RoleId": 5, "JobTitle": "ACCTC", "Description": "Accountant", "Category": null, "CategoryId": 0 }
]
})
});
kendo.bind($(".manage-roles"), roleViewModel);
I havent been able to figure out why the editor template is not binding the drop down. When I use the same markup for template rather than binding to the category name with ${Category}, it works for the template property. (For some reason this doesnt work in fiddle. But the exact same code works locally).
At this point I'll take any suggestions/approaches anything. I really wanted to use MVVM and not the .kendoGrid() syntax but I'll get over myself if it cannot be done. Anyone got any insight into whats going on with the editor template?
You can still build your grid using MVVM, but I think you have to make custom editors with a function call.
So instead of "editor" :kendo.template($("#someTemplate").html()), you just call a function.
edit: rolesViewModel.categoryEditor
See http://demos.kendoui.com/web/grid/editing-custom.html
See sample http://jsbin.com/UQaZaXO/1/edit
i have data view with following tpl.
<tpl for=".">
<tpl for="departments">
{title}
</tpl>
<tpl for="records">
<div class="thumb-wrap">
{name}
</div>
</tpl>
</tpl>
and my json redear like this
reader : new Ext.data.JsonReader(
{
root : 'data',
},
[
'departments' ,
'records'
]
),
and my item selectore in on my recordes
itemSelector : 'div.thumb-wrap',
and this is my json data
{
"success": true,
"data": [
{
"departments": [
{
"title": "name"
}
],
"records": [
{
"name": "name"
},
{
"name": "name"
}
]
},
{
"departments": [
{
"title": "name"
}
],
"records": [
{
"name": "name"
}
]
}
]
}
how cat i select my records in data view with extjs?
and how can i get selected recordes ?
i used getSelectedRecords() but it return array of departments and records.
tnx
I'm pretty sure that getSelectedRecords() is deprecated on ExtJS 4.
You can try doing something like this:
var records = data.getRecords();
That will return a Ext.data.Model[]. Than, you can access all the properties like an usual model:
record.get('departments');
record.get('records');
You are working against the system here with your record structure. DataView wants one record to correspond with one selectable item. But you want to have multiple selectable items inside one record. Doesn't work - the API was not designed for such a thing.
Your options seem to be:
Create a separate DataView component for each set of records.
Create your own DataView component that can handle grouping.
Use Grid with GroupingView. You have to change your record structure to something like below, but it's the easiest option to get working. Though... you have to sacrifice quite a bit of flexibility offered by DataView.
"data": [
{
{
"department": "Department 1"
"name": "record 1"
},
{
"department": "Department 1"
"name": "record 2"
},
{
"department": "Department 2"
"name": "record 1"
},
{
"department": "Department 2"
"name": "record 2"
},
]
}