- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一直在玩 ngrx/store,遇到了使用 Material-Datatable 显示数据的问题。虽然我能够使用效果从服务器检索数据,但似乎数据源没有识别出数据。我是新手,这似乎我找不到在这里遇到同样情况的任何人,所以值得输入。请注意:::我的商店/效果没有问题,我能够从服务器检索数据。
见下面的代码:
user1.component.ts
@Component({
selector: "app-user1",
templateUrl: "./user1.component.html",
styleUrls: ["./user1.component.scss"]
})
export class User1Component implements OnInit {
displayedColumns = ["firstName", "lastName", "contact", "email", "actions"];
displayedtransColumns = ["coin", "holdings", "price", "action"];
userDatabase: EmployeeModel[] = [];
dataSource: any | null;
index: number;
id: string;
selectedUserId: string;
users: Array<EmployeeModel> = [];
transactionListSub: Subscription;
transactionList: Observable<any>;
employees$: Observable<EmployeeModel[]>;
constructor(
public store: Store<fromStore.UserState>,
public httpClient: HttpClient,
public dialog: MatDialog
) {}
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@ViewChild("filter") filter: ElementRef;
ngOnInit() {
//dispatch action to load employees
this.loadData();
}
public loadData() {
/* this.store.select("employees").subscribe(state => {
console.log("Store state: " + state.);
});
*/
console.log("userDatabase from store: " + this.userDatabase);
this.store.select(fromStore.getAllEmployees).subscribe(arr => {
console.log("fromStore.getAllEmp: " + arr);
this.userDatabase = arr;
console.log("dataSource: " + this.userDatabase.length);
});
this.dataSource = new UserDataSource(
this.userDatabase,
this.paginator,
this.sort
);
this.store.dispatch(new fromStore.LoadEmp());
Observable.fromEvent(this.filter.nativeElement, "keyup")
.debounceTime(1000)
.distinctUntilChanged()
.subscribe(() => {
if (!this.dataSource) {
return;
}
this.dataSource.filter = this.filter.nativeElement.value;
});
}
addTransactionDialog() {
const dialogRef = this.dialog.open(AddDialogComponent, {
width: "300px"
});
dialogRef.afterClosed().subscribe(result => {
console.log(result);
});
}
}
export class UserDataSource extends DataSource<EmployeeModel> {
_filterChange = new BehaviorSubject("");
get filter(): string {
return this._filterChange.value;
}
set filter(filter: string) {
this._filterChange.next(filter);
}
filteredData: EmployeeModel[] = [];
renderedData: EmployeeModel[] = [];
constructor(
public _userDatabase: any,
public _paginator: MatPaginator,
public _sort: MatSort
) {
super();
// Reset to the first page when the user changes the filter.
this._filterChange.subscribe(() => (this._paginator.pageIndex = 0));
}
/** Connect function called by the table to retrieve one stream containing the data to render. */
connect(): Observable<EmployeeModel[]> {
// Listen for any changes in the base data, sorting, filtering, or pagination
const displayDataChanges = [
this._userDatabase,
this._sort.sortChange,
this._filterChange,
this._paginator.page
];
console.log("fromDatasource: " + this._userDatabase);
return Observable.merge(...displayDataChanges).map(() => {
// Filter data
this.filteredData = this._userDatabase
.slice()
.filter((user: EmployeeModel) => {
const searchStr = (user._id +
user.firstName +
user.lastName +
+user.contact,
user.email).toLowerCase();
return searchStr.indexOf(this.filter.toLowerCase()) !== -1;
});
// Sort filtered data
const sortedData = this.sortData(this.filteredData.slice());
// Grab the page's slice of the filtered sorted data.
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
this.renderedData = sortedData.splice(
startIndex,
this._paginator.pageSize
);
return this.renderedData;
});
}
disconnect() {}
/** Returns a sorted copy of the database data. */
sortData(user: EmployeeModel[]): EmployeeModel[] {
if (!this._sort.active || this._sort.direction === "") {
return user;
}
return user.sort((a, b) => {
let propertyA: number | string = "";
let propertyB: number | string = "";
switch (this._sort.active) {
case "_id":
[propertyA, propertyB] = [a._id, b._id];
break;
case "firstName":
[propertyA, propertyB] = [a.firstName, b.firstName];
break;
case "lastName":
[propertyA, propertyB] = [a.lastName, b.lastName];
break;
case "contact":
[propertyA, propertyB] = [a.contact, b.contact];
break;
case "email":
[propertyA, propertyB] = [a.email, b.email];
break;
}
const valueA = isNaN(+propertyA) ? propertyA : +propertyA;
const valueB = isNaN(+propertyB) ? propertyB : +propertyB;
return (
(valueA < valueB ? -1 : 1) * (this._sort.direction === "asc" ? 1 : -1)
);
});
}
}
user1.component.html
<div class="row">
<div class="col-md-8">
<mat-toolbar color="primary">
<span>Teammates</span>
<span class="spacer"></span>
Reload data:
<button mat-icon-button (click)="loadData()">
<mat-icon>refresh</mat-icon>
</button>
</mat-toolbar>
<div class="col-md-12 mat-elevation-z8">
<div class="form">
<mat-form-field floatPlaceholder="never" color="accent">
<input matInput #filter placeholder="Filter issues">
</mat-form-field>
</div>
<mat-table #table [dataSource]="dataSource" matSort class="mat-cell">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<ng-container matColumnDef="firstName">
<mat-header-cell *matHeaderCellDef mat-sort-header>FIRST NAME</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.firstName}}</mat-cell>
</ng-container>
<ng-container matColumnDef="lastName">
<mat-header-cell *matHeaderCellDef mat-sort-header>LAST NAME</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.lastName}}</mat-cell>
</ng-container>
<ng-container matColumnDef="contact">
<mat-header-cell *matHeaderCellDef mat-sort-header>CONTACT</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.contact}}</mat-cell>
</ng-container>
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef mat-sort-header>EMAIL</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.email}}</mat-cell>
</ng-container>
<ng-container matColumnDef="actions">
<mat-header-cell *matHeaderCellDef>
<!--<button mat-icon-button color="primary" (click)="addNew()" matTooltip="Add User" matTooltipPosition="right">
<mat-icon aria-label="Example icon-button with a heart icon">add</mat-icon>
</button>-->
<button class="btn btn-primary btn-sm" (click)="addNew()" matTooltip="Add User" matTooltipPosition="right">
<i class="fa fa-user-plus"></i>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let row; let i=index;">
<button class="btn btn-primary btn-sm" (click)="startEdit(i, row._id, row.firstName, row.lastName, row.contact, row.email)"
matTooltip="Edit User" matTooltipPosition="left">
<i class="fa fa-user-circle"></i>
</button>
<button class="btn btn-danger btn-sm" (click)="deleteItem(i, row._id, row.firstName, row.lastName, row.contact,row.email)"
matTooltip="Delete User" matTooltipPosition="right">
<i class="fa fa-user-times"></i>
</button>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
<mat-paginator #paginator [length]="dataSource.length" [pageIndex]="0" [pageSize]="10" [pageSizeOptions]="[5, 10, 25, 100]">
</mat-paginator>
</div>
</div>
<div class="col-md-4">
<mat-toolbar color="primary">
<span>Holdings</span>
</mat-toolbar>
<button class="btn btn-sm btn-primary" (click)="addTransactionDialog()" matTooltip="Add Transaction" matTooltipPosition="right"
color="primary">
<i class="fa fa-plus"></i>
</button>
<table class="table">
<tr>
<td>Coin</td>
<td>Holding</td>
<td>Action</td>
</tr>
</table>
</div>
</div>
最佳答案
好吧,经过一些 self 记忆,我发现不仅仅是我需要订阅@effects 才能让 EmployeeModel[ ] 显示在 mat-table 中,UserDataSource 也应该在订阅中实例化。我没想到会错过这个,希望也能帮助别人
.将进一步测试它......见下文。
@user1.component.ts
//dispatch action first
this.store.dispatch(new fromStore.LoadEmp());
console.log("userDatabase from store: " + this.userDatabase);
//then subscribe to selector of effect in order to convert observable response into EmployeeModel[] and instantiate the Datasource inside
this.store.select(fromStore.getAllEmployees).subscribe(arr => {
console.log("fromStore.getAllEmp: " + arr);
this.userDatabase = arr;
this.dataSource = new UserDataSource(
this.userDatabase,
this.paginator,
this.sort
);
console.log("dataSource: " + this.userDatabase);
});
关于angular - Mat-Table(数据源)+ 使用 Ngrx Store/Effects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49995159/
我试图通过预准备语句使用同一连接执行多个查询,但无法完全实现! 代码片段: public class PostPrReqDaoImpl implements PostPrReqDaoInterface
我目前有一个 2 列宽的 DataGridView,第一列是 DataGridViewTextBoxColumn,第二列是 DataGridViewComboBoxColumn。我还有一个预生成的通用
当我在一台机器上运行以下代码时,我得到了 org.apache.tomcat.dbcp.dbcp.BasicDataSource 的 tomcat 实现,当我在另一台机器上运行它时,我得到了 org.
不确定这是否可行,但这是我的设置。 我有一台带有双启动功能的笔记本电脑。 一个一个分区我有 WinXP 和 MSAccess 2000在另一个分区上,Ubuntu 10.04,带有 apache we
我试过: czmlDataSource.load(czmlurl).then(function(){ viewer.dataSource
我有一个 TableView 和一个数组源。当我在 viewDidLoad 方法中初始化数组时,tableview 显示数组中的数据。当我从 Internet 上的 XML 数据的 URL 填充数组时
我对 DataSource 和 SessionFactory 之间的区别感到困惑。 我认为SessionFactory是一个用于检索 session 的管理器(我猜这实际上是与数据库的连接)。 Dat
我想存储大量(~数千)个字符串并能够使用通配符执行匹配。 例如,这里是一个示例内容: Folder1 文件夹 1/Folder2 Folder1/* Folder1/Folder2/Folder3 文
我有一个 DataGridView 和一个从 SQL 表填充的一些对象的列表。我曾使用两种方法将列表绑定(bind)到网格。 1.直接使用列表到数据源 grdSomeList.DataSource =
我正在尝试在 DataGridView 中设置一些内容。看起来这应该很简单,但我遇到了麻烦。我想显示三列: 代码ID 代号 带有 TypeName 的 DisplayMember 和 TypeID 的
在我的 Config.groovy我把线: grails.config.locations = [ "classpath:app-config.properties"] 我在哪里设置数据源的定义。文件
为了这个问题,假设我有一个包含各种酒类的 Excel 数据源电子表格。 (Cell A) | (Cell B) Bacardi | Rum Smirnoff | Vodka Another Vodka
由于我经常使用第三方 API,我认为创建一些 Magento 模块以实现轻松连接和查询它们会很有帮助。理想情况下,您可以像这样查询 API... $data = Mage::getModel( 'to
将后台线程频繁更新的数据源与 GUI 主线程同步的最佳方法是什么? 我应该在每个方法调用周围放置一个 pthread 互斥体吗?这对我来说似乎也很重。 编辑:我正在寻找 10.5 解决方案 最佳答案
经过几个小时的点击和试用,在查看各种帖子寻求帮助后,这段代码终于起作用了。但我希望有人帮助我理解函数(i,dat),这意味着什么?下面是我的完整代码 - function get_assignedta
我使用的是 Wildfly 10.1 版本,有两个数据源,如下所示, jdbc:mysql://${dbhostn
我正在学习数据源,我想我开始理解它,但我不明白这一段。 据我所知,MySQL 和 PostgreSQL 等数据库供应商编写了自己的不同 DataSource 接口(interface)的实现。现在,这
我有一个关于 TomEE 和使用 tomee.xml 中指定的数据源的奇怪问题。值得注意的是,我使用的是 Netbeans、TomEE 和 MySQL。在 Ubuntu 13.04(Xubuntu 最
WWDC 2019 确实充满了 iOS 的新内容以及 TableViews 和 CollectionView 的新数据源,即 UITableViewDiffableDataSource . 我已成功将
我在独立模式下运行 jboss 并将 standalone.xml 中的数据源设置为以下内容: jdbc:sqlserver://myip:1433;databaseNam
我是一名优秀的程序员,十分优秀!