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.
Related
In MongoDb, with a Projection, I want to remove an array that contains one empty object [{}] resulting from a $unwind preserveNullAndEmptyArrays & group.
[{
"title": "Papaye",
"childrens": [{}],
"parents": [{
"title": "Arbres fruitiers",
"url": "/documents/plantes/arboriculture/arbres-fruitiers"
}
],
"url": "/documents/plantes/arboriculture/arbres-fruitiers/papaye"
},
{
"title": "Arbres fruitiers",
"childrens": [{
"title": "Tavelure",
"url": "/documents/maladies/tavelure"
},
{
"title": "Longane",
"url": "/documents/plantes/arboriculture/arbres-fruitiers/longane"
}],
"parents": [{
"title": "Arboriculture",
"url": "/documents/plantes/arboriculture"
}],
"url": "/documents/plantes/arboriculture/arbres-fruitiers"
}
Pipeline like :
var pipeline = [];
pipeline.push({$match:{url:/^\//}});
(...)
var proj = {};
proj.title = true;
proj.parents = true;
proj.url = true;
proj.parents = ???
proj.childrens = ???
pipeline.push({$project:proj});
db.getCollection('Pages').aggregate(pipeline)
Thanks in advance
Ok, I found the solution. Just test if url is null for the first array entry.
proj.childrens = {
"$cond", [
"$eq", [
"$arrayElemAt",["$childrens.url",0],
null
],
[],
"$childrens"
]
};
This is my JSON:
{
"title": "This an item",
"date":1000123123,
"data": [
{
"type": "html",
"content": "<h1>Hi there, this is a H1</h1>"
},
{
"type":"img",
"content": [
{
"title": "Image 1",
"url": "www.google.com/1.jpg",
"description":"This is the first image"
}
]
},
{
"type": "map",
"content": [
{
"lat":323434555,
"lng":4444343434,
"description":"this is just a place"
}
]
}
]
}
As you can see, the "data" fiel stores an array of objects where the "content" field is variable.
How should I model that in Mongoose?
This is how I defined my schema:
module.exports = mongoose.model('TestObject', new Schema({
title: String,
date: Date,
data: [
{
type: String,
content: Object
}
]
}));
And this is the response for the "data" field:
"data": [
{
"type":"img",
"content": [ "[object Object]" ]
},
{
"type":"map",
"content": [ "[object Object]" ]
}
]
What is the correct way to define a varying datatype for an object in Mongoose?
Maybe the Mixed type could meet your requirement
An "anything goes" SchemaType, its flexibility comes at a trade-off of it being harder to maintain. Mixed is available either through Schema.Types.Mixed or by passing an empty object literal.
data: [
{
type: String,
content: Mixed
}
]
Here is the simple table having three rows, and each row contains a DropdownBox with listItems. But the DropdownBox in the second row is empty. I want to hide the blank DropdownBox. Can we hide the empty DropdownBox from that row, so that it will look just a simple blank cell. Thanks in Advance!
Here, I have simple table.
var demoTbl = new sap.ui.table.Table({
visibleRowCount: 10,
width : "100%",
selectionMode: sap.ui.table.SelectionMode.Multi,
});
var systemColumn = new sap.ui.table.Column({
width:"12%",
label: new sap.ui.commons.Label({text: "Column Data", design:sap.ui.commons.LabelDesign.Bold}),
template: new sap.ui.commons.TextField({editable:false}).bindProperty("value", "name"),
sortProperty: "name",
filterProperty: "name",
sorted : false,
filtered : false
});
demoTbl.addColumn(systemColumn);
var inputListBox = new sap.ui.commons.ListBox();
inputListBox.bindAggregation("items","dropList",function(oId,oContext){
return new sap.ui.core.ListItem({
key: oContext.getProperty("id"),
text: oContext.getProperty("name")
});
});
var connectorIpColumn = new sap.ui.table.Column({
width:"12%",
label: new sap.ui.commons.Label({text: "Dropdown Data", design:sap.ui.commons.LabelDesign.Bold}),
template: new sap.ui.commons.DropdownBox({
"association:listBox" : inputListBox
})
});
demoTbl.addColumn(connectorIpColumn);
And, here is the Data -
var oData={
"dataList": [{
"id": 111,
"name": "Row1 Data",
"dropList": [
{"id": 1, "name": "Row1 dropDown Item1"},
{"id": 2, "name": "Row1 dropDown Item2"},
{"id": 3, "name": "Row1 dropDown Item3"},
{"id": 4, "name": "Row1 dropDown Item4"}
]
},
{
"id": 222,
"name": "Row2 Data",
"dropList": []
},
{
"id": 333,
"name": "Row3 Data",
"dropList": [
{"id": 8, "name": "Row3 dropDown Item1"},
{"id": 9, "name": "Row3 dropDown Item2"},
{"id": 10, "name": "Row3 dropDown Item3"}
]
}
]};
var mappingModel = new sap.ui.model.json.JSONModel({listData:oData});
sap.ui.getCore().setModel(mappingModel, "mappingModel");
demoTbl.setModel(mappingModel);
demoTbl.bindRows("/listData/dataList");
mappingModel.refresh(true);
var addSystemPage = new sap.m.Page("addSystemPageId", {
content:[demoTbl]
});
There are many ways reading the cells of the table and determining the dropdown values and explicitly setting the visibility. I would propose the best way is to
var oData={
"dataList": [{
"id": 111,
"name": "Row1 Data",
"dropVis" : true,
"dropList": [
{"id": 1, "name": "Row1 dropDown Item1"},
{"id": 2, "name": "Row1 dropDown Item2"},
{"id": 3, "name": "Row1 dropDown Item3"},
{"id": 4, "name": "Row1 dropDown Item4"}
]
},
{
"id": 222,
"name": "Row2 Data",
"dropVis" : false,
"dropList": []
},
{
"id": 333,
"name": "Row3 Data",
"dropVis" : true,
"dropList": [
{"id": 8, "name": "Row3 dropDown Item1"},
{"id": 9, "name": "Row3 dropDown Item2"},
{"id": 10, "name": "Row3 dropDown Item3"}
]
}
]};
You can see the json object has been modified to get one attribute dropVis this can manually filled you you based on dropList and finally bind this attribute to the call template
var connectorIpColumn = new sap.ui.table.Column({
width:"12%",
label: new sap.ui.commons.Label({text: "Dropdown Data", design:sap.ui.commons.LabelDesign.Bold}),
template: new sap.ui.commons.DropdownBox({
visible : "{dropVis}",
"association:listBox" : inputListBox
})
});
The visibility is bound directly and it should work.
You can make use of formatter to toggle visibility based on length of dropList Array.
template: new sap.ui.commons.DropdownBox({
visible: {
path: 'dropList',
formatter: function(aList) {
return aList ? !!aList.length : false;
}
}
});
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");
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"
},
]
}