Display Only Selected Rows in sap.m.Table - sapui5

I have a table created by using sap.m.Table and a filter in the headerToolbar.
When the user clicks on the filter button, a list, which contains the key field of the table, should display with all available rows.
When the user selects and clicks on OK in the dialog, only
those rows should be displayed in the table.
The Dialog has list of values along with OK and CANCEL buttons.
I am trying to achieve it by changing the model of the table after user selection but could not get it. Can someone please let me know where I went wrong and if any other better way to do it?
var list = new sap.ui.getCore().byId("ls2");
var sel = list.getSelectedItems();
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oModel);
var oElement = sap.ui.getCore().getElementById("table1");
oElement.setModel(oModel);`
After OK, the table should display values which are selected from the list.

You are trying to set the columns that are shown by the Table, but instead you are changing the filters you want to manage, or even the oData model that feeds the table. That's wrong.
Use the property useTablePersonalisation="true" in your table.
It will appear a "control" button above your table. Click it and go to the tab "Columns" (it should be default). Then choose the columns you want to be displayed.
Tell me if it is enough for you.

Related

Oracle Apex: how to exclude a selected PopUp LOV row from its Query and refresh it dynamiclly

i had an IG, it has a PopUp LOV column to select value, the LOV Query is in Shared Component. is it possible if user select '01-My First Row' from LOV this will not available in next row or disabled to select and similar for other selected values? if yes, how it can done? filtering LOV Query on runtime refrencing selected value(s) in IG or anything else? help needed.
To be able to decide if a value from LOV is selected before it is submitted to the server-side (before saving the IG in that case), you need to handle that using client-side code(javascript).
As an idea, you can create a dynamic action that will execute a Javascript code on LOV value selection.
In that Javascript code, use
var widget = apex.region('yourgridID').widget();
var grid = widget.interactiveGrid('getViews', 'grid');
var model = grid.model;
model.forEach(function(r) {
var record = r;
console.log(record);
})
Then you can observe the record on your browser's console to see the column value when an item of LOV is selected.
Then you would need to use JQUERY for disabling the LOV list values.

Hide column name in personalization dialog box based on condition

I have p13n dialog box in a table, where I am displaying 2 columns coming from the backend.
Now, I want to implement condition in column 2. For example,
if(mainCondition === true)
{
display column2;
}
else
{
hide columns2;
}
The issue here is, these column names are coming from CDS view & with entity set.
I can, of course, hide them completely using the setIgnoreFromPersonalisation method, however, I don't know how can I implement condition on these field's visibility property.
Thanks.
Since the two columns are coming from the backend, you can add Filter to the model to filter out the ones to be hidden.

Add empty rows in a tableviewer

I want to use a "Add" button to add empty rows in the table using table viewer. After adding a new row, the user can edit it. How can I implement this design? Thanks!
You should add the rows to the data that your content provider returns in the getElements method using something that the label provider will show as empty. You then call refresh on the table.
For editing you will use the normal EditingSupport and make sure it can deal with empty entries.

sap.m.Table removeColumn does not delete the corresponding items

If I remove one Column using a sap.m.Table from a standard view the corresponding items are still available. The problem here is that the ordering is wrong after I delete a column here.
Lets say I want to delete the "Historie"-Column, the corresponding items are still available. How can I delete one column with the items of one column here?
The problem here looks like that:
As you can see in the picture below I have deleted some columns and also the "Historie"-Column. The corresponding items are still available.
How to solve this and delete the matching items here using sap.m.Table?
I tried to remove the Columns by removeColumn(oCol) from the API: sap.m.Table
I think this is a bug with sap.m.Table.
For your problem, you can use the visible property of column to hide the column from view. Though it will not remove the column from the table.
var oTable = this.byId('idTable');
var oDeleteColumn = oTable.getColumns()[0]; //fetch the column you want to hide
oDeleteColumn.setVisible(false);
removeColumn() removes the column only from the table's <column> aggregation, but not from the data.
If it is an option for you, than use Table Personalization:
Table personalization can be used to modify the display and settings
of a table.
It is a UI pattern that is used to change one or more of the following
attributes:
Visibility of columns
Order of columns
Sorting
Grouping
Filtering
Sample

web2py SQLFORM.factory defaults not updating

I have an SQLFORM.factory on a page that I use to(among other things) update a particular field in a table. That field is a drop down table I made like so
Field('visibility',requires=IS_IN_SET(['everyone','subscribers','friends','nobody']))
So the field in the SQLFORM.factory looks the same. The difference is that I want the default in the SQLFORM.factory to be the current value of that field in a particular table. by making a default. I do a query on the desired entry on the table, select that field, and that becomes my default, the selected option. Perfect the first time you load it up.
I do the update after the form accepts like so and the update works functionally:
if subForm.accepts(request,session,dbio=True):
if myForm.vars.visible != theDefault:
db(row).update(visibility = subForm.vars.visibility)
If you submit the page the selected option is not the current value of that field in the table, it's always the one it was previous. If I look at my database admin the table updated fine but I could not fetch the right option to select as my default. If my default was 'everyone' and then I select and submit 'friends' then the selected when the page reload after the submit is still 'everyone' If I then select and submit 'nobody', after the refresh it is 'friends'.
If it helps, I am displaying the view this SQLFORM.factory is in in and iFrame as part of a bigger page.
After many hours, here's how you do it(sorta hackey but it works)
#This is a kludge to get the right default visibility selected
if request.vars.visible == None:
visibleDefault = theDefault
else:
visibleDefault = request.vars.visible
form = SQLFORM.factory(
FIELD(Field('visible',requires=IS_IN_SET(['everyone','subscribers','friends','nobody'],zero=None),default=visibleDefault),
table_name='table')
if form.accepts(request,session,dbio=True):
if form.vars.visible != theDefault:
db(row).update(visibility = form.vars.visible)