@activewidgets/js 中文文档教程

发布于 3年前 浏览 13 项目主页 更新于 3年前

ActiveWidgets/JS • Datagrid

npm versionnpm 下载Github 问题Github repo

ActiveWidgets 是一个多框架 UI 组件库。 此软件包为 javascript / 无框架 环境提供datagrid 组件

现场演示 / 开发者指南 / API 参考

Datagrid demo

Installation

添加 @activewidgets/js到您的项目依赖项 -

> npm i --save @activewidgets/js

Usage

mount 函数导入您的应用程序 -

import { mount } from "@activewidgets/js";

现在,假设您已将占位符 ax-datagrid 标记添加到

<ax-datagrid>Loading...</ax-datagrid>

页面占位符位置 -

const rows = [
    { message: 'Hello, World!' }
];

mount('ax-datagrid', { rows });

实例 | github 上的源 | 在 Codesandbox 上编辑

为了快速制作原型,该包也可通过 ActiveWidgets CDN 获得-

<script src="https://cdn.activewidgets.com/js"></script>

在这种情况下,mount 函数在 ActiveWidgets.JS 全局命名空间中可用。

var mount = ActiveWidgets.JS.mount;

var rows = [
    { framework: 'none', source: 'CDN', language: 'ES5'}
];

mount('ax-datagrid', { rows: rows });

实例 | github 上的源 | 在 Codesandbox 上编辑

Mount function

mount function 应该是目标元素(或选择器)。 第二个参数是一个属性对象。 目标元素 tagName 定义组件 ID。

mount('#grid1', { columns, rows });

占位符元素标记必须是 ax-datagrid

<ax-datagrid id="grid1"></ax-datagrid>

mount 函数返回 updatedestroy 方法。

const { update } = mount('#my-grid', { columns, rows });

//...

update({ rows: newRows });

Data properties

您必须提供 rows 属性到数据网格以显示一些数据。 每个 column 对象的属性定义了数据的呈现方式 -

  • field - where the cell data comes from (string|function)
  • header - column header (string|object)
  • width - column width (number, in pixels)
  • align - cell text alignment (left|right|center)
  • format - number/date format (string|function)
  • fixed - fixed (true/false) for columns on the left or right side

style(字符串|对象)或 className 属性允许更改样式列和单元格元素。

const columns = [
  { header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true },
  { header: 'Company Name', field: 'companyName', width: 160 },
  { header: 'Contact', field: 'contactName', width: 120 },
  { header: 'Title', field: 'contactTitle', width: 120 },
  { header: 'Address', field: 'address', width: 120, align: 'right' }
];

const rows = northwind.customers;

mount('ax-datagrid', { columns, rows });

实例 | github 上的源 | 在 Codesandbox 上编辑

User events

除了数据网格发出的标准 DOM 键盘和鼠标事件合成的 mouse 事件,可以更轻松地找到受用户操作影响的元素 -

function onMouse({ row }){
    alert(`row ${ row.key } clicked!`);
}

mount('ax-datagrid', { onMouse, columns, rows }); // put event handlers together with props

实例 | github 上的源 | 在 Codesandbox 上编辑

More info


ActiveWidgets

ActiveWidgets/JS • Datagrid

npm versionnpm downloadsGithub issuesGithub repo

ActiveWidgets is a multi-framework UI component library. This package provides datagrid component for javascript / no-framework environments.

Live demo / Developer guide / API reference

Datagrid demo

Installation

Add @activewidgets/js to your project dependencies -

> npm i --save @activewidgets/js

Usage

Import mount function into your app -

import { mount } from "@activewidgets/js";

Now, assuming that you've added a placeholder ax-datagrid tag to the page

<ax-datagrid>Loading...</ax-datagrid>

Mount an actual ActiveWidgets component at the placeholder position -

const rows = [
    { message: 'Hello, World!' }
];

mount('ax-datagrid', { rows });

Live example | Source on github | Edit on Codesandbox

For quick prototyping the package is also available over ActiveWidgets CDN -

<script src="https://cdn.activewidgets.com/js"></script>

In this case the mount function is available at ActiveWidgets.JS global namespace.

var mount = ActiveWidgets.JS.mount;

var rows = [
    { framework: 'none', source: 'CDN', language: 'ES5'}
];

mount('ax-datagrid', { rows: rows });

Live example | Source on github | Edit on Codesandbox

Mount function

The first argument for the mount function should be the target element (or selector). The second argument is a properties object. The target element tagName defines the component ID.

mount('#grid1', { columns, rows });

The placeholder element tag must be ax-datagrid

<ax-datagrid id="grid1"></ax-datagrid>

The mount function returns update and destroy methods.

const { update } = mount('#my-grid', { columns, rows });

//...

update({ rows: newRows });

Data properties

You have to provide columns and rows properties to the datagrid to show some data. The properties of each column object define how the data will be rendered -

  • field - where the cell data comes from (string|function)
  • header - column header (string|object)
  • width - column width (number, in pixels)
  • align - cell text alignment (left|right|center)
  • format - number/date format (string|function)
  • fixed - fixed (true/false) for columns on the left or right side

The style (string|object) or className properties allow to change the styling of the column and cell elements.

const columns = [
  { header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true },
  { header: 'Company Name', field: 'companyName', width: 160 },
  { header: 'Contact', field: 'contactName', width: 120 },
  { header: 'Title', field: 'contactTitle', width: 120 },
  { header: 'Address', field: 'address', width: 120, align: 'right' }
];

const rows = northwind.customers;

mount('ax-datagrid', { columns, rows });

Live example | Source on github | Edit on Codesandbox

User events

In addition to the standard DOM keyboard and mouse events the datagrid emits composite mouse event which makes it easier to find the elements affected by the user action -

function onMouse({ row }){
    alert(`row ${ row.key } clicked!`);
}

mount('ax-datagrid', { onMouse, columns, rows }); // put event handlers together with props

Live example | Source on github | Edit on Codesandbox

More info


ActiveWidgets

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文