BlackBerry Cascades: How do i load data into a ListView - blackberry-10

Hello I have a simmiliar question as this one:
BlackBerry 10 Cascades: How do I load data into a DropDown?
The only thing i want to know is how to do this with a ListView instead of a dropdown?
Thanks in advance!

The ListView displays data from a DataModel which is an abstract data type. Which specific type of data model you use depends on the source of your data. You place your data in the appropriate data model then assign the data model to the ListView.

To load data into a dropdown, instead of a listview, use this code:
DropDown {
id: dropdown
attachedObjects: [
ComponentDefinition {
id: compDefDD
Option {
description: "your default value for each Option"
}
},
DataSource {
id: dropDownDataSource
// Load the data from an SQL database, based on a specific query
source: "asset:///database.sql
query: "select * from <yourtable>"
onDataLoaded: {
//the method is the code above
for (var i = 0; i < data.length; i ++) {
var option = compDefDD.createObject();
option.text = data[i].SQLcolumn1;
option.value = data[i].SQLcolumn2;
dropdown.add(option);
}
}
onError: {
console.debug(errorMessage + " : " + errorType);
}
}
]
onCreationCompleted: {
dropDownDataSource.load();
}
}
In this example I load data from a sql database. If you use another source of the data see page reference for more details.

Related

Access field names from firebase realtime db through flutter

I am trying to retrieve data from firebase realtime database in my flutter app. My data looks something like this :
This is my code :
var uid = user?.uid;
final ref = FirebaseDatabase.instance.ref('uids/$uid/sessions');
ref.onValue.listen((event) {
for (final child in event.snapshot.children) {
var dataObject = child.value.toString();
print(dataObject);
}
}, onError: (error) {});
It gives me this output :
I/flutter (16144): {2:9: Example728, 3:15: Example644, 1:45: Example, 2:11: Example184, 2:7: Example}
I/flutter (16144): {2:16: Example440, 2:26: Example124, 2:22: Example515}
I want to extract information from this jsonObject. But I have 0 idea how to do it. Do I have to make a model? If yes then how? Because the fields are actually time stamps. And I would want to access them as well as I have to display it on the screen with the date (5-11-2022 and 6-11-2022) as well.
Use this code inside the listen
//dataObject = child.value
Map dataObject = {
"5-11-2022": {
"2:9": "Example728",
"3:15": "Example644",
"1:45": "Example",
"2:11": "Example184",
"2:7": "Example",
},
"6-11-2022": {
"2:16": "Example440",
"2:26": "Example124",
"2:22": "Example515",
},
};
for (MapEntry item in dataObject.entries) {
String day = item.key.toString();
debugPrint("day: $day");
for (MapEntry item2 in dataObject[item.key].entries) {
String hour = item2.key.toString();
String value = item2.value.toString();
debugPrint("hour: $hour value: $value");
}
}

agSelectCellEditor dynamic list

I am using ag-grid and for any given row I would like the dropdown in one column to be dependent on the value of a different column. Can I do that with agSelectCellEditor or do I have to create a custom component.
You can define your cellEditorParams function in a way that returns different values depending on values of another column.
Here is a sample from the ag-grid site -
cellEditor : 'agSelectCellEditor';
cellEditorParams: function(params) {
var selectedCountry = params.data.country;
if (selectedCountry==='Ireland') {
return {
values: ['Dublin','Cork','Galway']
};
} else {
return {
values: ['New York','Los Angeles','Chicago','Houston']
};
}
}
Take a look at this example from official docs. You will have to replace agRichSelectCellEditor with agSelectCellEditor

Hierarchial JSON model and UI5

I am creating a demo application with JSON data and UI5. The idea (in a nutshell) is provide various information views for a selected item. I am using IconTabBar control. I have created an example scenario so (hopefully) I can explain the problem more clearly.
1.IconTabBar's first tab has list of employees and user can select one by selecting a radio button on the left
2.This takes the user to the next tab that displays say, sales view. The user can click on any tab and move to the respective view.
3.User can modify the information in any view. If the users forgets or ignores to Save the data, the tab color is set to Red.
4.User can Save the data.
5.Some of the views have information in master detail format.
The problem(s) I am facing are:-
1.How to filter the model data based on the item selected in the table?
2.How to update the filtered data and set back to model?
3.I also would like to know whether the data is structured correctly
I am using following code to update the binding path after company is selected. The GREP function is not returning correct values for proposals. It returns ONLY 1 proposal for E001 whereas it should return 2. It doesn't work properly for orders either. I am not sure whether the data is structured correctly.
var oModel_Data = oJSONDataModel.getData();
var oView_Data = oViewDataModel.getData();
var aModelData = oModel_Data[sSelected_Key];
var aViewData = oView_Data[sSelected_Key];
aViewData = jQuery.grep(aModelData, function(data, index) {
return data.id === sSelected_id
})[0];
oView_Data[sSelected_Key]=aViewData;
oViewDataModel.setData(oView_Data);
oViewDataModel.refresh(true);
I am using following code to check whether user has changed data.
var oView_Data = oViewDataModel.getData();
var oModel_Data = oJSONDataModel.getData();
var aViewData = oView_Data[in_sKey];
var aModelData = oModel_Data[in_sKey];
aModelData.forEach(function(item, index, array) {
var valueView = aViewData;
if (item.id === sSelected_id){
//The code here need to consider complex(nested) data types
//Thus it should check type of not only valueView and item
//but also their each and every child elements
/*---------Temporary Solution---------------------*/
var sViewValue = JSON.stringify(valueView);
var sItem = JSON.stringify(item);
var bSameData = sViewValue === sItem;
if (bSameData==true){
flag_data_changed=false;
}else{
return flag_data_changed=true;
}
}
});
My json model is as below.
{
"employees": [
{"id":"E0001" ,
"name":"Alec Stewert"
},
{"id":"E0002" ,
"name":"Debra Manning"
}
],
"sales": [
{"id":"E0001" ,
"sale_q1":"10000",
"sale_q2":"3000",
"sale_q3":"8000",
"sale_q4":"2000"
},
{"id":"E0002" ,
"sale_q1":"8000",
"sale_q2":"3000",
"sale_q3":"7000",
"sale_q4":"5000"
}
],
"proposal":[
{"id":"E0001",
"fi_q":"Q2",
"value":"12000",
"customer":"6000"
},
{ "id":"E0001",
"fi_q":"Q2",
"value":"8000",
"customer":"2300"
}
],
"key_orders": [
{"id":"E0001",
"order_hdr":
[
{"id":"O0001",
"fi_q":"Q1",
"value":"2000",
"customer":"2000"
},
{"id":"O0002",
"fi_q":"Q1",
"value":"2000",
"customer":"2000"
}
],
"order_dtl":[
{
"id":"O0001",
"itm":"Item X",
"Qty":"100",
"rate":"20"
}
]
},
{"id":"E0002",
"order_hdr":
[
{"id":"O0011",
"fi_q":"Q1",
"value":"2000",
"customer":"5000"
},
{"id":"O0012",
"fi_q":"Q1",
"value":"1000",
"customer":"5000"
}
],
"order_dtl":[
{
"id":"O00011",
"itm":"Item Z",
"Qty":"200",
"rate":"10"
}
]
}
]
}
I have investigated online and in SAP Help but failed to understand what needs to be done. Any help is appreciated.
1.How to filter the model data based on the item selected in the table?
If you prepare the JSONModel you can use the Filter
2.How to update the filtered data and set back to model?
If you bind the table to the JSONModel, by default the JSNOModel is 2 way binding so any edited data will be in the JSONModel
3.I also would like to know whether the data is structured correctly
Go through the Example of the Table So you will get an idea of the Model and binding model to the Table

How to access BSON data "cells" in Meteor?

I have a problem:
In Meteor, I would like to be able to first fetch data from mongodb and then be able to update/edit the fetched data before returning it to the template.
So for example I have movies in the database in the following format:
{ name: "...", released: "..." }
In the code i would do something like this:
var movie = Movies.findOne({name: "Inception"});
Then I would like to get and edit the "release" data from the movie -variable. How to do it?
Use a transform:
return Movies.find({}, {transform:function(movie) {
if(movie.release) movie.release = movie.release + " _ This has been appended to release".
return movie;
});

How to display JSONModel data using "sap.ui.table.DataTable"?

I'm trying to bring data from an internal table in a ABAP program into an SAPUI5 application.
From the ABAP side, I have converted the required data into JSON format and sending it across like it is mentioned in the a guide.
I have written the following code in the 'Read' section of the controller
$.ajax({
type: 'GET',
url: 'http://socw3s1er67.solutions.glbsnet.com:8000/sap/bc/Z_tets_json?sap-client=950',
success: function(data) {
alert(data[1].PROJECT);
alert(data[0].MANDT);
var oModel_Projects = new sap.ui.model.json.JSONModel();
oModel_Projects.setData({ modelData: data });
}
});
Sample JSON response from the server:
[
{
"MANDT": "PJ1",
"PROJECT": "Test Project1",
"DESCRIPTION": ""
},
{
"MANDT": "PJ2",
"PROJECT": "Test Project2",
"DESCRIPTION": ""
}
]
The alerts seem to be working fine and are returning expected data from the internal tables.
I want to know: how to bind this data into a particular table using models?
Well, your code looks ok, but there are other parts, which are missing, and there might be a problem there...
How is your table constructed - ?
It should be:
var table = new sap.ui.table.DataTable({
title: 'My first table',
width: '100%'
});
Do you make following calls to connect table and model?
table.setModel(oModel_Projects);
table.bindRows("modelData");
Are you properly creating columns of the table?
label = new sap.ui.commons.Label({ text: 'Client' });
template = new sap.ui.commons.TextView({ text: '{MANDT}' });
col = new sap.ui.table.Column({ label: label, template: template });
table.addColumn(col);
Is table properly placed into HTML using placeAt method?
Updated the answer after your clarification:
Try this parser:
var html = "<table><tr><td>MANDT</td><td>PROJECT</td><td>DESCRIPTION</td></tr>";
for(var index in data){
html+="<tr><td>"+data[index].MANDT+"</td><td>"+data[index].PROJECT+" </td><td>"+data[index].DESCRIPTION+"</td></tr>";
}
html+="</table>";
//now you can insert this html into some div like as follows: $("#div1").html(html);
Or google for some jquery gridview as I suggested in the comment.