如何使用 Angular2 数据表

2024-05-02

找不到任何使用教程angular2-data-table图书馆在这里:https://github.com/swimlane/angular2-data-table https://github.com/swimlane/angular2-data-table

该文档似乎缺乏简单的示例。

谁能给我一个在 angular2 中使用数据表的简单例子


出于这个确切原因,我不建议使用该库。我已经工作了几周,试图在项目中使用它,但由于缺乏文档,它几乎无法使用。

话虽如此,这里是一个相对简单的例子。这使用了 Angular2快速开始 https://angular.io/docs/ts/latest/quickstart.html作为基础,我所做的就是通过 npm 添加 angular2-data-table 。你需要抓住公司.json https://github.com/swimlane/angular2-data-table/blob/master/assets/data/company.json来自 Github 并将其放在项目的根目录中。

包.json

{
  "name": "liw-reports",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "lite": "lite-server",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "licenses": [
    {
      "type": "MIT"
    }
  ],
  "dependencies": {
    "@angular/common": "~2.1.2",
    "@angular/compiler": "~2.1.2",
    "@angular/core": "~2.1.2",
    "@angular/forms": "~2.1.2",
    "@angular/http": "~2.1.2",
    "@angular/platform-browser": "~2.1.2",
    "@angular/platform-browser-dynamic": "~2.1.2",
    "@angular/router": "~3.1.2",
    "@angular/upgrade": "~2.1.2",
    "angular2-data-table": "^1.4.1",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.41",
    "zone.js": "^0.6.26"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.7",
    "@types/node": "^6.0.46",
    "concurrently": "^3.1.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.9"
  }
}

系统js.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: 'app',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
            'angular2-data-table': 'npm:angular2-data-table/release/index.js',
            // other libraries
            'rxjs': 'npm:rxjs',
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

应用程序模块.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Angular2DataTableModule } from 'angular2-data-table';

import { AppComponent } from './app.component';

@NgModule({
    declarations: [AppComponent],
    imports: [BrowserModule, Angular2DataTableModule],
    bootstrap: [AppComponent]
})
export class AppModule {}

应用程序组件.ts

import {
    Component
} from '@angular/core';


@Component({
    moduleId: module.id,
    selector: 'my-app',
    template: `
    <div>
      <h3>Fluid Row Heights</h3>
      <datatable
        class="material"
        [rows]="rows"
        [columns]="columns"
        [columnMode]="'force'"
        [headerHeight]="50"
        [footerHeight]="50"
        [rowHeight]="'auto'">
      </datatable>
    </div>
  `
})
export class AppComponent {

    rows = [];

    columns = [{
        prop: 'name'
    }, {
        name: 'Gender'
    }, {
        name: 'Company'
    }];

    constructor() {
        this.fetch((data) => {
            this.rows = data;
        });
    }

    fetch(cb) {
        const req = new XMLHttpRequest();
        req.open('GET', `./company.json`);
        req.onload = () => {
            cb(JSON.parse(req.response));
        };
        req.send();
    }

}

索引.html

<html>

<head>
    <title>Angular QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="/node_modules/angular2-data-table/release/datatable.css" />
    <link rel="stylesheet" type="text/css" href="/node_modules/angular2-data-table/release/material.css" />
    <link rel="stylesheet" href="styles.css">
    <!-- 1. Load libraries -->
    <!-- Polyfill for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
        System.import('app').catch(function(err) {
            console.error(err);
        });
    </script>
</head>
<!-- 3. Display the application -->

<body>
    <my-app>Loading...</my-app>
</body>

</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Angular2 数据表 的相关文章

随机推荐

  • 获取 grails 中单击的提交按钮的名称

    在表单上我有两个提交按钮
  • PHP、MySQL、PDO 事务 - fetchAll() 可以在 commit() 之前吗?

    更多交易问题 我现在拥有的是一堆串在一起的查询 如果有任何失败 都会手动反转 代码块1 stmt1 db gt prepare Update table1 set col col 1 if stmt1 db gt execute stmt2
  • R mapbox / 带有动画和 shapefile 的绘图

    我正在制作一个动画 显示地图上绘制的空间数据 并带有基于日期的动画滑块 除此之外 我想绘制一个随时间变化的形状文件 我的动画在没有 shapefile 的情况下也能正常工作 绘制标记和形状文件不会显示形状文件 似乎是两者之间的某种脱节add
  • 如何在 MongoDB 中存储 blob 数据?

    我想知道是否可以在 mongodb 中插入 blob 数据 这个过程是什么 是否需要任何其他软件 在数据库中存储大文件是没有问题的 使用mongofiles See mongodb com 上的文章 https www mongodb co
  • 正则表达式 IPv6 验证和可选的方括号?

    大家好 这里的正则表达式新手 我正在尝试编写一个验证 IPv6 地址的正则表达式 我还没有添加端口部分 我想先让地址部分工作 这是我到目前为止所拥有的 0 9A Fa f 这使得左括号和右括号是可选的 但正如您所看到的 它们是独立可选的 有
  • 如何使用 hostPath 将单个文件映射到 kubernetes pod 中?

    我有一个自己的 nginx 配置 home ubuntu workspace web conf由脚本生成 我更喜欢把它放在下面 etc nginx conf d除了default conf 下面是nginx yaml apiVersion
  • JS专用鼠标按键

    我的鼠标侧面有两个按钮 其默认行为是 后退 和 前进 我想知道的是是否可以在 JavaScript 中检测这些鼠标按钮的点击 或者这些按钮是否是类似于键盘的 播放 音量调高 和 无线开 关 的 特殊 按钮纽扣 我不知道任何特定的鼠标事件 但
  • 修改变量后动态重新导入 Sass 部分

    我正在开发一个利用 Sass 预编译的 Twitter Bootstrap 的项目 每次覆盖变量时 我都必须重新导入 bootstrap sass文件到我的项目主样式表以使覆盖生效 您是否知道如何使此过程自动进行 以便每次修改变量时立即生效
  • AJAX 与 Facebook 身份验证

    我已经构建了一个完全基于 AJAX 的应用程序 它没有页面刷新并使用 AJAX 加载所有内容 现在我想以一种不会重定向用户进行页面刷新的方式嵌入 Facebook 身份验证 目前 Facebook 的工作方式如下 用户通过单击 Facebo
  • 无法使用 sysctl 更改每个进程的最大打开文件数

    我的实际极限是1024 ulimit a core file size blocks c 0 data seg size kbytes d unlimited scheduling priority e 0 file size blocks
  • 指定随机粒子起始颜色而不进行动画更改?

    有没有办法让粒子根据当前的 颜色渐变 产生随机的每个粒子颜色 粒子在其生命周期内不会改变颜色 它们只是在出生时从 颜色渐变 的某个地方被分配了一种颜色 并保持该颜色直到它们死亡 其结果将是出生时的粒子与从红色到蓝色的混合颜色的混合 在我的测
  • 在无头模式下独立运行 Unity,同时捕获屏幕截图

    我需要创建一个在无头模式下运行的统一项目 使用 batchmode 命令 但它必须捕获屏幕截图 例如每一秒并将它们写到一个文件中 我知道在无头模式下 您需要强制调用 Camera Render 才能渲染任何内容 在捕获第一个屏幕截图后 时间
  • Python Numpy TypeError:输入类型不支持 ufunc 'isfinite'

    这是我的代码 def topK dataMat sensitivity meanVals np mean dataMat axis 0 meanRemoved dataMat meanVals covMat np cov meanRemov
  • Apache CXF - WS 解决如何设置 From、ReplyTo、Headers

    我有一个问题 我们正在尝试使用 Apache CXF 实现 WS Addressing 我可以设置一些标头 例如 To 或 Action 但我找不到设置其他标头 例如 From ReplyTo 或 FaultTo 的方法 有人知道该怎么做吗
  • 在Python中解析空选项

    我有一个应用程序 允许您将事件数据发送到自定义脚本 您只需布置命令行参数并指定什么事件数据与什么参数相匹配 问题是这里没有真正的灵活性 您制定的每个选项都将被使用 但并非每个选项都必须有数据 因此 当应用程序构建要发送到脚本的字符串时 某些
  • height: calc(100%) 在 CSS 中无法正常工作

    我有一个 div 我想填充主体的整个高度减去设定的像素数 但我无法得到height calc 100 50px 上班 我想这样做的原因是我有一些元素具有基于一些不同标准的动态高度 例如标题的高度根据它可以包含的不同元素而变化 然后 内容 d
  • ANSI 转义码无法正确显示

    我有以下定义 define ANSI COLOR RED e 31m define ANSI COLOR GREEN e 32m define ANSI COLOR YELLOW e 33m define ANSI COLOR BLUE e
  • SQL Server - 评估期已过期错误

    昨天我的电脑上安装的 SQL Server 2014 试用期结束了 我决定使用 Express 版本并卸载 SQL Server 2014 并安装 Express 版本 但是当我打开SQL Server Management Studio时
  • 如何从网络客户端获取状态码?

    我正在使用WebClient类将一些数据发布到 Web 表单 我想获取表单提交的响应状态代码 到目前为止我已经找到了如果出现异常如何获取状态代码 Catch wex As WebException If TypeOf wex Respons
  • 如何使用 Angular2 数据表

    找不到任何使用教程angular2 data table图书馆在这里 https github com swimlane angular2 data table https github com swimlane angular2 data