首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >aurelia bridge kendo网格刷新

aurelia bridge kendo网格刷新
EN

Stack Overflow用户
提问于 2016-07-19 14:49:48
回答 0查看 630关注 0票数 1

我正在尝试在我的应用程序中使用Aurelia KendoUi桥。在我的代码中,我有一个返回新KendoDataSource的服务:

代码语言:javascript
复制
export class KendoDataSource {

ToKendoDataSource(data: any, recordCount: number, pageSize: number, currentPage: number): any {
    return {
        transport: {
            read: (p) => {
                p.success({ data: data, recordCount: recordCount });
            }
        },
        pageSize: pageSize,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true,
        schema: {
            data: (result) => {
                console.log('Transforming data to kendo datasource.');
                return result.data;
            },
            total: (result) => {
                return result.recordCount;
            }
        }
    };
}

}

这是我的viewModel:

代码语言:javascript
复制
@inject(HttpService, KendoDataSource, EventAggregator)

导出类GroupList {

代码语言:javascript
复制
grid: any;
gridVM: any;
datasource: any;
pageable: any;
subscriber: any;
paginationDetailsRequest: PaginationDetailsRequest;
test: string;

constructor(private httpService: HttpService, private kendoDataSource: KendoDataSource, private eventAggregator: EventAggregator) {
    this.httpService = httpService;
    this.kendoDataSource = kendoDataSource;
    this.eventAggregator = eventAggregator;

    this.paginationDetailsRequest = new PaginationDetailsRequest(4, 1);
    this.GetGroups(this.paginationDetailsRequest);

    this.datasource = {
        transport: {
            read: {
                url: 'PersonGroup/GetGroups',
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                dataType: 'json'
            },
            parameterMap: function (data, type) {
                if (type == "read") {
                    let paginationDetails = new PaginationDetailsRequest(data.pageSize, data.page);

                    if(data.sort && data.sort.length > 0){
                        paginationDetails.orderBy = data.sort[0].field;
                        paginationDetails.OrderDesc = (data.sort[0].dir == 'desc'); 
                    }

                    console.log(this.datasource);

                    return JSON.stringify(paginationDetails);
                }
            }
        },
        schema: {
            data: "data.currentPageData",
            total: "data.totalCount"
        },
        pageSize: 2,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    };
};

attached() {
    this.subscriber = this.eventAggregator.subscribe('Search', response => {
        this.search(response);
    });
}

activate() {


    this.pageable = {
        refresh: true,
        pageSizes: true,
        buttonCount: 10
    };
}

GetGroups(paginationDetails: PaginationDetailsRequest): void {

    this.httpService.post('PersonGroup/GetGroups', paginationDetails)
        .then(response => response.json())
        .then(groups => {
            console.log(groups);
            if (groups.succeeded) {
                this.datasource = this.kendoDataSource.ToKendoDataSource(groups.data.currentPageData, groups.totalCount, groups.pageSize, groups.currentPage);
                this.grid.setDataSource(this.datasource); // initialize the grid
            }
            else {
                //TODO: Show error messages on screen
                console.log(groups.errors);
            }
        })
        .catch(error => {
            //TODO: Show error message on screen.
            console.log(error);
        });
}

search(searchDetails: Filter) {
    console.log(searchDetails);
    this.paginationDetailsRequest.filters.push(searchDetails);
    console.log(this.paginationDetailsRequest);
    this.GetGroups(this.paginationDetailsRequest);
}

detached() {
    this.subscriber.dispose();
}

}

我知道kendo没有双向数据绑定,但我正在尝试找到一种方法,当我过滤数据时,数据源发生变化时刷新网格。谢谢。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38451353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档