Get values from sap.m.Table - sapui5

Is it possible to get the values from a sap.m.Table without clicking a specific entry?
With an event I can get the values by the actual context but what I need is to get the whole items with the specific characteristic.
For example my table has the following columns (column D is not invisible):
A B C D
with the entries shown below:
A B C D
1 2 3 4
4 b 2 1
What I need now is the first row for example:
1 2 3 4
I want to write something like
table.getItem("A")[0]
to get 1 as a result.
How can I achieve this?

You can get all the Items in the table using getItems(), which will give you an Array of Items. You can then get the bindingContext for any of the Items.
var iRowIndex = 0; //For First row in the table
var oTable = this.getView.byId("myTable"),
oModel = oTable.getModel(),
aItems = oTable.getItems();
if(iRowIndex < aItems.length){
oModel.getProperty("ColA",aItems[iRowIndex].getBindingContext());
}

Related

Expand rows based on the integer values of a column while parsing through the values in remainder columns to separate values among the inserted rows

What I need is to insert rows according to the integer value in a column while parsing through the values in the remaining columns to separate their values on the new inserted rows.
I have a table like this
ID
Household
User Count
Show 1
Show 2
Show 3
Show 4
123
House 1
2
Shooter
Dark
1234
House 2
4
Awake
Arrow
Lou
Ozark
And I need an expanded table where each row represents an individual user
ID
Household
User Count
Show 1
Show 2
Show 3
Show 4
123
House 1
1
Shooter
123
House 1
1
Dark
1234
House 2
1
Awake
1234
House 2
1
Arrow
1234
House 2
1
Lou
1234
House 2
1
Ozark
I need to solve this problem using either Google Apps Script or PostgreSQL.
In your situation, when Google Apps Script is used, how about the following sample script?
Sample script:
Please copy and paste the following script to the script editor of Spreadsheet and save the script. And, please set the source and destination sheet names.
function myFunction() {
const srcSheetName = "Sheet1"; // Please set source sheet name.
const dstSheetName = "Sheet2"; // Please set source sheet name.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(srcSheetName);
const [header, ...values] = sheet.getDataRange().getValues();
const res = [header, ...values.flatMap(([a, b, c, ...d]) => {
const len = d.length;
return [...Array(c)].map((_, i) => {
const temp = [...Array(i).fill(null), d[i]];
return [a, b, 1, ...temp, ...Array(len - temp.length).fill(null)];
});
})];
ss.getSheetByName(dstSheetName).getRange(1, 1, res.length, res[0].length).setValues(res);
}
When this script is run, the values are retrieved from source sheet, and the values are converted, and then, the converted values are put to the destination sheet. In this case, when your sample input table is used, the sample output table can be obtained.
If you want to use this script as a custom function, how about the following sample script? When your showing input table is used, please put a custom function like =SAMPLE(A1:G3) to a cell. By this, the result values are returned.
function SAMPLE(v) {
const [header, ...values] = v;
return [header, ...values.flatMap(([a, b, c, ...d]) => {
const len = d.length;
return [...Array(c)].map((_, i) => {
const temp = [...Array(i).fill(null), d[i]];
return [a, b, 1, ...temp, ...Array(len - temp.length).fill(null)];
});
})];
}
Note:
This sample script is prepared from your sample input and output tables. So, when you changed the table or your actual Spreadsheet is different from your sample input table, the script might not be able to be used. Please be careful about this.
Reference:
map()

read up a table and analyze the elements matlab

I am trying to realize my idea in matlab.
I consider two column A and B.
A=data(:,1)
B=data(:,5)
the data look like:
A B
1 1
2 1
3 1
... ...
100 20
... ...
150 30
151 1
... ...
The values in column A are timepoints.
I start with the first element in column A. It schould be A(1,1) and look on the first element in the column B B(1,1). If B(1,1)==1its true,if not its false. Then I increase consider the second raw of the column A and second raw of the column B and so on until the last raw of A and B.
How can I construck this loop??
You can just consider B likes the following:
result = (B == 1);
The result would be the same size of B such as you want. Nowm you can get the value of A on result likes the following:
valid_times = A(result);

How to automatically generate sequent numbers when using a form

Ahab stated in 2010: the complex looking number based on the Timestamp has one important property, the number can not change when rows are deleted or inserted.
As long as the submitted data is not changed by inserting deleting rows the simple formula =ArrayFormula(ROW(A2:A) - 1) may be the easiest one to use.
For other situations there is no nice reliable solution. :(
Now we live in 2015. Maybe times have changed?
I need a reliable way to number entries using a form.
Maybe a script can do the trick? A script that can add 1 to each entry?
That certain entry has to keep that number even when rows are deleted or inserted.
I created this simple spreadsheet in which I added 1,2, and 3 manually,please have a look:
https://docs.google.com/spreadsheets/d/1H9EXns8-7m9oLbCrTyIZhLKXk6TGxzWlO9pOvQSODYs/edit?usp=sharing
The script has to find the maximum of the former entries, which is 3, and then add 1 automatically.
Who can help me with this?
Grtz, Bij
Maybe a script can do the trick? A script that can add 1 to each
entry?
Yes, that would be what you need to resort to. I took the liberty of entering this in your example ss:
function onEdit(e) {
var watchColumns = [1, 2]; //when text is entered in any of these columns, auto-numbering will be triggered
var autoColumn = 3;
var headerRows = 1;
var watchSheet = "Form";
var range = e.range;
var sheet = range.getSheet();
if (e.value !== undefined && sheet.getName() == watchSheet) {
if (watchColumns.indexOf(range.getColumn()) > -1) {
var row = range.getRow();
if (row > headerRows) {
var autoCell = sheet.getRange(row, autoColumn);
if (!autoCell.getValue()) {
var data = sheet.getDataRange().getValues();
var temp = 1;
for (var i = headerRows, length = data.length; i < length; i++)
if (data[i][autoColumn - 1] > temp)
temp = data[i][autoColumn - 1];
autoCell.setValue(temp + 1);
}
}
}
}
}
For me the best way is to create a query in a second sheet pulling everything from form responses in to second column and so on. then use the first column for numbering.
In your second sheet B1 you would use:
=QUERY(Form!1:1004)
In your second sheet A2 you would use:
=ARRAYFORMULA(if(B2:B="",,Row(B2:B)-1))
I made a second sheet in your example spreadsheet, have a look at it.

How can I retrieve a real position of row after filter?

I have a table with a filter.
If I use this code to select the row that I clicked before add a filter it retrieve incorrect index:
handleRowPress : function(evt){
var selectedRowNum = evt.getSource().indexOfItem(evt.getParameter("listItem"));
...
},
For example if I have 5 results A B C D E and after filter I have C and E, whith previous code if I click on E, selectedRowNum is 2, but I want 5!
You can get the binding context path of your selected list item and then get the index of the row.
var itemContextPath = evt.getParameter("listItem").getBindingContextPath();
var indexOfRow = parseInt(itemContextPath.substring(itemContextPath.lastIndexOf("/")+1, itemContextPath.length));
Regards,
Allen

Remove data from struct bigger than a certain value

I have a struct, that's a <1x1 struct>, and I'm trying to edit a field in the struct based on the values. The field is called GeoDist_Actual and the struct is called GeoDist_str. The field GeoDist_Actual is a <262792x1 double>, and this is the code I was trying to use in order to get rid of the values that are greater than 1.609344e+05.
i =1;
for i=i:size(GeoDist_str.GeoDist_Actual)
if GeoDist_str.GeoDist_Actual(i,1 > 1.609344e+05
GeoDist_str.GeoDist_Acutal(i,1) = [];
end
end
How would I append or alter this code in order to make it function like I'm aiming? I considered setting all the values to 0, but I'm going to have to go backwards from this in order to get back GPS values, doing a reverse-Vincenty(spherical) calculation, and I'd like to just completely get rid of the values that don't comply with the if condition.
If I can narrow down the question at all, let me know, and thank you for your help in advance!
Edit: I've noticed that when I changed out the section
GeoDist_str.GeoDist_Actual(i,1) = [];
for
GeoDist_str.GeoDist_Actual(i,1) = 0;
It didn't actually solve anything, instead it didn't access the field "GeoDist_Actual" within the struct "GeoDist_str", it just created a mirror field with values of 0.
Consider this example:
% a 10-by-1 vector
x = [1;2;3;4;5;6;7;8;9;10];
% remove entries where the value is less than five
x(x<5) = [];
This is called logical indexing, no need for loops.
Consider the following simple example:
A.a = 1:5;
A =
a: [1 2 3 4 5]
now delete all elements bigger 3;
A.a = A.a( ~(A.a > 3) );
A =
a: [1 2 3]
or alternatively:
A.a( A.a > 3 ) = []
For your case it's a little more bulky:
GeoDist_str.GeoDist_Actual = ...
GeoDist_str.GeoDist_Actual( ...
~(GeoDist_str.GeoDist_Actual > 1.609344e+05) )