0

如何清晰地使用内部 API > 0.10.9?在 0.10.6 版本中,我们在项目中使用此导入来修改数据网格中的内部过滤器:

import {DatagridStringFilterImpl} from "clarity-angular/data/datagrid/built-in/filters/datagrid-string-filter-impl"; 
import {RegisteredFilter} from "clarity-angular/data/datagrid/providers/filters";

至少在 0.10.9 版本中不能再这样写了。编译器最终出现以下错误:

ERROR in ./src/app/common/DatagridUtils.ts
Module not found: Error: Can't resolve 'clarity-
angular/data/datagrid/providers/filters' in 'C:\java\workspace\rimc\rimc-web\src\main\webapp\angularapp\src\app\common'
 @ ./src/app/common/DatagridUtils.ts 5:16-74
 @ ./src/app/sampleData/sample-data.component.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

 ERROR in ./src/app/common/DatagridUtils.ts
 Module not found: Error: Can't resolve 'clarity-angular/data/datagrid/built-in/filters/datagrid-string-filter-impl' in 
'C:\java\workspace\project\angularapp\src\app\common'
  @ ./src/app/common/DatagridUtils.ts 4:36-121
  @ ./src/app/sampleData/sample-data.component.ts
  @ ./src/app/app.module.ts
  @ ./src/app/index.ts
  @ ./src/main.ts
  @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
 webpack: Failed to compile.

我最近报告说,由于错误 1512 分辨率,我们想升级到 0.10.10。

编辑:被问到为什么要使用内部 API 而不是对自定义过滤器的内置支持,这是我的回答:这是因为在我的情况下,我想使用由数据网格上方的单独输入字段表示的全文过滤器。填充数据网格中的此字段后,将触发刷新并将请求发送到后端。诀窍是,在触发请求之前,我将全文过滤器值从单独的输入字段附加到数据网格过滤器的内部值。所有这些都借助在提到的版本中更改的内部 API。如果有其他方法可以实现此功能,我将很高兴为您服务。

编辑2:(源代码)

import {
Datagrid, DatagridPropertyComparator, DatagridPropertyStringFilter, DatagridStringFilter,
State
} from "clarity-angular";
import {DatagridStringFilterImpl} from "clarity-angular/data/datagrid/built-in/filters/datagrid-string-filter-impl";
import {FiltersProvider, RegisteredFilter} from "clarity-angular/data/datagrid/providers/filters";


export default class DatagridUtils {

static fulltextPropertyName: string = '_fulltext';

static getState(datagrid: Datagrid, fulltext: any) {

    const state: State = {};

    let activeFilters;

    if (datagrid && datagrid['filters']) {
        const page = datagrid['page'];
        if (page.size > 0) {
            state.page = {from: page.firstItem, to: page.lastItem, size: page.size};
        }

        const sort = datagrid['sort'];
        if (sort.comparator) {
            if (sort.comparator instanceof DatagridPropertyComparator) {
                /*
                 * Special case for the default object property comparator,
                 * we give the property name instead of the actual comparator.
                 */
                state.sort = {by: (<DatagridPropertyComparator>sort.comparator).prop, reverse: sort.reverse};
            } else {
                state.sort = {by: sort.comparator, reverse: sort.reverse};
            }
        }

        let filtersProvider = datagrid['filters'];
        let fulltextFilter = this.getFulltextFilter(filtersProvider);
        if (!fulltextFilter) {
            fulltextFilter = new DatagridStringFilterImpl(new DatagridPropertyStringFilter(this.fulltextPropertyName, false));
            // rucni registrace, aby se neregistroval observer, ktery nam vse zacykluje
            const registered = new RegisteredFilter(fulltextFilter, () => {
            });
            filtersProvider['_all'].push(registered);
        }
        if (typeof fulltext === 'string') {
            fulltextFilter['value'] = fulltext;
            // zmena filtru zpusobi prechod na 1. stranku
            page.current = 1;
        }

        activeFilters = filtersProvider.getActiveFilters();
        if (activeFilters.length > 0) {
            state.filters = [];
            for (const filter of activeFilters) {
                if (filter instanceof DatagridStringFilterImpl) {
                    const stringFilter = (<DatagridStringFilterImpl>filter).filterFn;
                    if (stringFilter instanceof DatagridPropertyStringFilter) {
                        /*
                         * Special case again for the default object property filter,
                         * we give the property name instead of the full filter object.
                         */
                        state.filters.push({
                            property: (<DatagridPropertyStringFilter>stringFilter).prop,
                            value: (<DatagridStringFilterImpl>filter).value
                        });
                        continue;
                    }
                }
                state.filters.push(filter);
            }
        }
    }

    return state;

}

static getFulltextFilter(filtersProvider): DatagridStringFilterImpl {
    let all = filtersProvider['_all'];
    for (const filter of all) {

        if (filter.filter instanceof DatagridStringFilterImpl) {
            const stringFilter = (<DatagridStringFilterImpl>filter.filter).filterFn;
            if (stringFilter instanceof DatagridPropertyStringFilter) {
                if ((<DatagridPropertyStringFilter>stringFilter).prop === this.fulltextPropertyName) {
                    return filter.filter;
                }
            }
        }
    }

    return null;
}

}

4

0 回答 0