Responsive mat-grid-list - html

I intend to use a mat-grid-list with a set of responsive cards.
My problem is that I'm having errors with the breakpoints and I can't understand.
Can anyone help me?
DEMO
ts
cardLayout = this.breakpointObserver
.observe([Breakpoints.Handset, Breakpoints.Tablet])
.pipe(
map(({ matches }) => {
if (matches) {
return {
columns: 1,
miniCard: { cols: 1, rows: 1 },
chart: { cols: 1, rows: 2 },
table: { cols: 1, rows: 4 },
};
}
return {
columns: 4,
miniCard: { cols: 1, rows: 1 },
chart: { cols: 2, rows: 2 },
table: { cols: 4, rows: 4 },
};
})
);
Error
Bad Breakpoint size

That's because you have multiple subscriptions to your observable, so the values are resolved sequentially.
So when your observable emits, first subscriber (mat-grid-list) gets updated to the new layout, change detection is fired and DOM is updated. All of this happens BEFORE the mat-grid-tile gets updated, so you end up with colspans from the previous layout on children while parent has a single column.
You can use *ngIf with as syntax to store the value locally and refer to the stored value in the children elements, e.g.
<ng-container *ngIf="cardLayout | async as layout">
<mat-grid-list [cols]="layout.columns" rowHeight="200px">
<mat-grid-tile
[colspan]="layout.miniCard.cols"
[rowspan]="layout.miniCard.rows"
>
...
</mat-grid-tile>
</mat-grid-list>
</ng-container>
This allows for a single subscription (which should be more performant as well), increases readability and removes unnecessary sequential DOM updates.
Forked stackblitz here.

Related

Dash dataTable Conditional Formatting for specific cell value doesn't work

I have a multiple header data frame and I succeeded to extract the column names by two functions.
I have comparison rows in my data every third line (that compares the two rows values before it) and contains one of the values: "Imporoved", "Not Improved" etc...
For example the table looks something like that:
measure1 | measure2
previouse 70 | 80
new 60 | 100
compare IMPROVED | SIGNIFICANT DEGRADED
I'm trying to add conditional formatting that will color a cell in a certain way if it equals to one of the options of the comparison values. The conditional formatting does not work in a way it does not raise an error but does not display any of the highlighting.
I tried the following code:
style_data_conditional=
[{
'if': {
'filter_query': '{{{col}}} = "SIGNIFICANT DEGRADED"'.format(
col=col),
'column_id': col
},
'backgroundColor': 'black',
'color': '#FF1616'
} for col in columns_names
]
+
[
{
'if': {
'filter_query': '{{{col}}} = "NOT IMPROVED"'.format(
col=col),
'column_id': col
},
'backgroundColor': 'CD7B05',
'color': '#D3C4AF'
} for col in columns_names
]
+
[
{
'if': {
'filter_query': '{{{col}}} = "IMPROVED"'.format(
col=col),
'column_id': col
},
'backgroundColor': '82C729',
'color': '#F4FFE7'
} for col in columns_names
]
+
[
{
'if': {
'filter_query': '{{{col}}} = "SIGNIFICANT IMPROVED"'.format(
col=col),
'column_id': col
},
'backgroundColor': '8FFF0C',
'color': 'white'
} for col in columns_names
]
At first I had a problem with accessing the column names because of the multi headers, but I fixed it and "columns_names" is a list containing the actual columns names (for example columns_names = [['counter1', 'Average'],['counter1', 'max'],...]).
I don't know why the it won't display, the table remains white.
Will appreciate some help!

Flutter iOS flutter_swipe_action_cell not updating UI after deleting cell

I have a ListView containing 5 elements in the following order:
Section Header
Valid Item 0
Valid Item 1
Section Header
Invalid Item 0
When I swipe to delete Valid Item 0, the ListView length becomes 4 instead of 5 (as expected), the UI appears in the order below, with only 3 items. I have also determined that each element in the ListView.builder, is being returned correctly (in the order above, except for Valid Item 0, as expected). Each Widget is being build as expected.
Section Header
Section Header
Invalid Item 0
The UI appears correctly until I call setState(() {}). Once it is called, Valid Item 1 is removed from the UI, but not the data source. If I switch the current display to a different Scaffold (as shown in the video below), then switch back, the UI shows correctly again. Strange.
Using the flutter_swipe_action_cell package, I have added a delete button that appears when the cell is swiped to the left.
I followed this example:
SwipeAction(
title: "delete",
onTap: (CompletionHandler handler) async {
/// await handler(true) : will delete this row
/// And after delete animation, setState will called to
/// sync your data source with your UI
await handler(true);
list.removeAt(index);
setState(() {});
},
color: Colors.red
)
With this code:
SwipeAction(
icon: Container(
margin: const EdgeInsets.only(bottom: 4),
child: const Icon(
Icons.delete,
size: 30,
)
),
title: "Delete",
performsFirstActionWithFullSwipe: true,
onTap: (CompletionHandler handler) async {
print("Delete Profile (valid # ${index - 1})");
await handler(true);
(data["valid"] as List).removeAt(index - 1);
setState(() {});
},
color: Colors.red
)
This is a recording of my issue:
I ended up figuring it out myself after several hours of trial and error.
The key component here is literally key. I didn't realize the purpose of the key initially. It seems to be used to coordinate which cell is being deleted on the UI with its corresponding data. The key for each SwipeActionCell should reference the exact same data child which will be deleted.
SwipeActionCell(
key: ObjectKey(data["valid"]![privateIndex]),
...
)
where privateIndex is the index for the list item in that section, ignoring any section headers and previous sections. Eg:
1. Section Header listIndex: 0 privateIndex: N/A
2. Valid Item 0 listIndex: 1 privateIndex: 0
3. Valid Item 1 listIndex: 2 privateIndex: 1
4. Section Header listIndex: 3 privateIndex: N/A
5. Invalid Item 0 listIndex: 4 privateIndex: 0
and where data is:
Map<String,List<dynamic>> data = {
"valid": [
{"title":"Valid Item 0"},
{"title":"Valid Item 1"}
],
"invalid": [
{"title":"Invalid Item 0"}
]
}

How do I delete nested JSONModel row from a SAPUI5 table using dialog box?

I have a SplitApp application that consists of categories and items under each category whose json structure resembles the one below:
{
"stations":[{
station_id: "1",
station_name:"Nairobi",
items: [
{
station_id: "1",
item_id: 1,
item_name: Nairobi item A
},
{
station_id: "1",
item_id: 2,
item_name: Nairobi item B
}
,
{
station_id: "1",
item_id: 3,
item_name: Nairobi item C
}
]
},
{
station_id: "2",
station_name:"Berlin"
}]
On the master page are the stations and the detail page consists of the items displayed as a table. The ColumnListItem is active and hence it opens a dialog box where am performing other actions, one of which includes an update to MySQL database which necessitates the need for the clicked row to disappear.
The dialog box is correctly displayed with the table bindings.
I want to upon clicking a button in the dialog box to update the database, the row is deleted from the json model. My model is nested and most of the examples such as this,this,this,this appear to show deleting a row where json is non-nested.
Here is my code which deletes a whole nested structure instead of a single path of a whole nested structure. E.g.if I want to delete station_id 1-item_id 3, the whole of station_id 1 together with all the items under it is deleted.
var that = this;
var stationModel= that.getView().getModel("station")
var oModel = stationModel.getData();
var oTable = this.getView().byId("oList");
var oSelectedItemPath = oDialog.getBindingContext("station").getObject();
//the oDialog was bound through the following when a table row is clicked
//var path = evt.getSource().getBindingContext("station").getPath();
//oDialog.bindElement("station>"+path);
var index = $.map(oModel.stations, function(obj, index) {
if (obj === oSelectedItemPath) {
return index;
}
});
oModel.stations.splice(index, 1);
that.getView().getModel("station").setData(oModel);
How can I tweak the code so that I only delete the selected path only through the dialog box. Example if I delete item 3 station 1, only that item should be deleted.
No deletion is happening in the database.

kendo grid sorting not working in Chrome

I have problem with sorting in Kendo grid. Here is my example: http://dojo.telerik.com/iVATi
In IE sorting works fine: default view and asc sorting view are the same: first going elements starting with symbols, second elements with a-z letters, third elements with а-я letters. But in Chrome and Firefox I see three other results:
1). default view: first going element starting with symbols, second elements with a-z letters, third elements with а-я letters. (correct!)
2). asc sorting: first going elements starting with symbols, second elements with а-я letters, third elements with a-z letters. (bad!)
3). desc sorting: first going elements with z-a letters, second elements with я-а letters, third sorted elements with symbols. (correct!)
The problem is caused by Chrome's unstable sorting and adding an auxiliary data field is the standard way to resolve this limitation.
In case you don't want to add indexes in the data items array, it is also possible to add them on the fly with schema.parse:
var dataSource = new kendo.data.DataSource({
data: [
{ Name: "!asdgad" },
{ Name: "#sgjkhsh" },
{ Name: "adfadfka" },
{ Name: "tgjbndgnb" },
{ Name: "xsdfvks" },
{ Name: "абдваолптрв" },
{ Name: "пролрлитс" },
{ Name: "юатроваро" },
{ Name: "юдвлоитвт" }
],
schema: {
parse: function(data) {
for (var i = 0; i < data.length; i++) {
data[i].index = i;
}
return data;
}
}
});
You will still need to use a custom comparer function though.
I solved this problem. I extended sorted datasource with index field and added comparer-function by index for field name:
http://dojo.telerik.com/UKimo
May be exists other solutions?

Filtering a dropdown in Angular

I have a requirement for a select html element that can be duplicated multiple times on a page. The options for these select elements all come from a master list. All of the select elements can only show all of the items in the master list that have not been selected in any of the other select elements unless they just were duplicated.
When you select a new item from a duplicated select element, it seems to select the option after the one you selected even though the model still has the correct one set. This always seems to happen in IE11 and it happens sometimes in Chrome.
I realize this sounds convoluted, so I created a jFiddle example.
Try these steps:
Select Bender
Click the duplicate link
Select Fry (on the duplicated select)
Notice that the one that is selected is Leela but the model still has Fry (id:2) as the one selected
Can anyone tell me how I might get around this or what I might be doing wrong?
Here is the relevant Angular code:
myapp.controller('Ctrl', function ($scope) {
$scope.selectedIds = [{}];
$scope.allIds = [{ name: 'Bender', value: 1},
{name: 'Fry', value: 2},
{name: 'Leela', value: 3 }];
$scope.dupDropDown = function(currentDD) {
var newDD = angular.copy(currentDD);
$scope.selectedIds.push(newDD);
}
});
angular.module('appFilters',[]).filter('ddlFilter', function () {
return function (allIds, currentItem, selectedIds) {
//console.log(currentItem);
var listToReturn = allIds.filter(function (anIdFromMasterList) {
if (currentItem.id == anIdFromMasterList.value)
return true;
var areThereAny = selectedIds.some(function (aSelectedId) {
return aSelectedId.id == anIdFromMasterList.value;
});
return !areThereAny;
});
return listToReturn;
}
});
And here is the relevant HTML
<div ng-repeat="aSelection in selectedIds ">
Duplicate
<select ng-model="aSelection.id" ng-options="a.value as a.name for a in allIds | ddlFilter:aSelection:selectedIds">
<option value="">--Select--</option>
</select>
</div>
Hi I have just made a small change in your dupDropDown function as follows
$scope.dupDropDown = function(currentDD) {
$scope.selectedIds.push({});
}
Please check if this works for you.