首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Angular Material 2:编辑记录后如何刷新md表?

Angular Material 2是一个开发框架,用于构建现代化的、响应式的Web应用程序。它基于Angular框架,并提供了一套丰富的UI组件和工具,用于创建美观、易于使用的用户界面。

在Angular Material 2中,如果要在编辑记录后刷新md表格,可以采取以下步骤:

  1. 首先,确保你已经正确地绑定了数据到md表格上。这可以通过将数据存储在一个数组中,并使用数据绑定将其传递给md表格的dataSource属性来实现。
  2. 当你编辑记录时,更新相应的数据对象。这可以通过监听编辑事件或使用表单控件来实现。
  3. 在数据对象更新后,调用md表格的renderRows()方法来刷新表格。这将重新渲染表格,并显示更新后的数据。

以下是一个示例代码片段,展示了如何在Angular Material 2中实现编辑记录后刷新md表格的过程:

代码语言:txt
复制
import { Component, ViewChild } from '@angular/core';
import { MatTable } from '@angular/material/table';

@Component({
  selector: 'app-table',
  template: `
    <table mat-table [dataSource]="data">
      <!-- 表格列定义 -->
      <ng-container matColumnDef="name">
        <th mat-header-cell *matHeaderCellDef>Name</th>
        <td mat-cell *matCellDef="let record">{{ record.name }}</td>
      </ng-container>
      <ng-container matColumnDef="age">
        <th mat-header-cell *matHeaderCellDef>Age</th>
        <td mat-cell *matCellDef="let record">{{ record.age }}</td>
      </ng-container>

      <!-- 表格行定义 -->
      <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
      <tr mat-row *matRowDef="let record; columns: displayedColumns;"></tr>
    </table>
    <button (click)="editRecord()">Edit Record</button>
  `,
})
export class TableComponent {
  @ViewChild(MatTable) table: MatTable<any>;

  data = [
    { name: 'John', age: 25 },
    { name: 'Jane', age: 30 },
    { name: 'Bob', age: 35 },
  ];

  displayedColumns = ['name', 'age'];

  editRecord() {
    // 编辑记录的逻辑,更新数据对象
    // ...

    // 刷新表格
    this.table.renderRows();
  }
}

在上述示例中,我们使用了Angular Material的MatTable组件来展示数据,并通过@ViewChild装饰器获取了对表格的引用。在editRecord()方法中,我们可以执行编辑记录的逻辑,并在更新数据对象后调用this.table.renderRows()来刷新表格。

这样,当你编辑记录后,md表格将会重新渲染,并显示更新后的数据。

对于Angular Material 2的更多信息和详细介绍,你可以访问腾讯云的相关文档和官方网站:

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

jTable插件辅助资料

==============================================jTable插件================================================ 【】引入jtable <link rel="stylesheet" type="text/css" href="../jtable/themes/lightcolor/blue/jtable.min.css" /> <script type="text/javascript" src="../jtable/jquery.jtable.min.js"></script> <script type="text/javascript" src="../jtable/localization/jquery.jtable.zh-CN.js"></script> 注:jTable插件需要jquery UI插件。之前要引入jQuery和jQueryUI 【】Servlet生成JSON结果 collegeList=collegeBusiness.getListByAll(); //定义数据返回JSON map Map<String, Object> jsonMap = new HashMap<String, Object>(); jsonMap.put("Result", "OK"); jsonMap.put("Records", collegeList); JSONObject result=JSONObject.fromObject(jsonMap); HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out=response.getWriter(); out.println(result.toString()); out.flush(); out.close(); 【】jtable要求的返回格式 {  "Result":"OK",  "Records":[   {"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},   {"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},   {"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},   {"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}  ] } 【】当出现异常后的jTable要求的结果 {    "Result":"ERROR",    "Message":"异常信息字符串" } 【】jTable的语法  $('#MyTableContainer').jtable({             //General options comes here             actions: {                 //Action definitions comes here             },             fields: {                 //Field definitions comes here             }             //Event handlers... });      【】jtable初始化 1.定义jTable显示的区域div

2.在JS中初始化jTable //定义部门表格 $('div#departmentmaincontent').jtable({            title: '部门列表',            selecting: true, //Enable selecting            multiselect: false, //not Allow mu

04
领券