首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ngx-数据表模板问题

Ngx-数据表模板问题
EN

Stack Overflow用户
提问于 2018-05-07 07:17:51
回答 1查看 3.1K关注 0票数 0

我正在使用一个在我的角度组件中呈现表格数据(下图)。除了无法从'Action‘标题列中移除排序函数之外,一切正常工作。在检查它时,我可以看到它在span class = "datatable-header-cell-wrapper“下使用span class =”sort“。知道如何删除排序函数吗?我增加了以下代码:

schedule-management.component.html:

代码语言:javascript
运行
复制
<ol class="breadcrumb">
    <li class="breadcrumb-item"><a [routerLink]="['/home']">Home</a></li>
    <li class="breadcrumb-item"><a [routerLink]="['/cldtools']">Cloud Runner Tools</a></li>
    <li class="breadcrumb-item active">Schedule Management</li>
</ol>

<div class="row" style="margin-top:20px;">
    <div class="col-lg-12">
        <h2>All Schedules</h2>
    </div>
</div>

<div class="row" style="margin-top:20px;">
    <div class="col-lg-12">
        <div class="dropdown">
            <button class="btn btn-primary">Create New </button>
            <div class="dropdown-content">
                <a [routerLink]="['/schedulemanagement/autoStartStopVm']" [queryParams]="{dropDownListSelectedItem:'AutoStart'}">AutoStart</a>
                <a [routerLink]="['/schedulemanagement/autoStartStopVm']" [queryParams]="{dropDownListSelectedItem:'AutoShutdown'}">AutoShutdown</a>
                <!--<a href="#">Auto Scale</a>-->
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <!--<div style="overflow-x:scroll; overflow-y:scroll; width: 100%">-->
        <ngx-datatable #table
                       class='datatable'
                       [sortType]="'single'"
                       [columns]="columns"
                       [columnMode]="'flex'"
                       [headerHeight]="40"
                       [footerHeight]="50"
                       [rowHeight]="'auto'"
                       [groupRowsBy]="'isCurrentDate'"
                       [limit]="10"
                       [rows]='rows'
                       [groupExpansionDefault]="true"
                       [scrollbarH]="true">

            <ngx-datatable-group-header [rowHeight]="60" #myGroupHeader>
                <ng-template let-group="group" let-expanded="expanded" ngx-datatable-group-header-template>
                    <div style="padding-left:5px;">
                        <a title="Expand/Collapse Group"
                           (click)="toggleExpandGroup(group)">
                            <b>{{group.value[0].isCurrentDate === true? 'Scheduled for Today':'Scheduled for other days'}}</b>
                        </a>
                    </div>
                </ng-template>
            </ngx-datatable-group-header>

            <ng-template #sortableColumnTemplate let-sort="sortFn" let-column="column" ngx-datatable-header-template>
                <span (click)="sort()" class="sort-fullwidth">{{column?.name}}</span>
                <input class="filter-box" placeholder='' (keyup)='updateFilter($event)' />
            </ng-template>

            <ng-template #dateColumn let-row="row" let-value="value" ngx-datatable-cell-template>
                <div>{{value | date:"short"}}</div>
            </ng-template>

            <ng-template #actionRowTemplate let-row="row" let-value="value" ngx-datatable-cell-template>
                <div style="display:block; text-align:center;">
                    <!-- <a title="copy"><i class="glyphicon glyphicon-copy"></i></a>                    -->
                    <a title="delete" (click)="deleteWarningModal.show();scheduleToDelete = value"><i class="glyphicon glyphicon-remove"></i></a>
                </div>

            </ng-template>
        </ngx-datatable>
    </div>
</div>

    <loading-spinner *ngIf="showSpinner"></loading-spinner>
    <modal #deleteWarningModal>
        <div class="app-modal-header">
            Warning
        </div>
        <div class="app-modal-body">
            Are you sure you want to delete the schedule?
        </div>
        <div class="app-modal-footer">
            <button type="button" (click)="deleteSchedule()" class="btn btn-primary">Yes</button>
            <button type="button" (click)="deleteWarningModal.hide()" class="btn btn-secondary">No</button>
        </div>
    </modal>

schedule-management.component.ts:

代码语言:javascript
运行
复制
import { Component, Inject, OnInit, ViewChild, TemplateRef } from '@angular/core';
import { GridComponent } from '../shared/grid.component';
import { SchdedulingDetails } from '../../models/schedulingDetails';

//Services
import { ScheduleManagementService } from '../../services/schedulemanagement.service';
import { ToasterNotificationService } from '../../services/toasterNotification.service';
import { ModalComponent } from '../shared/modal.component';


@Component({
    selector: 'schedulemanagement',
    templateUrl: './schedule-management.component.html',
    styleUrls: ['./schedule-management.component.css', '../shared/grid.component.css']
})
export class ScheduleManagementComponent extends GridComponent implements OnInit {

    constructor(private _schedManagementService: ScheduleManagementService,
        private notificationsService: ToasterNotificationService) {
        super();
    }

    scheduleToDelete: string;
    showSpinner: boolean = true;
    @ViewChild('deleteWarningModal') deleteWarningModal: ModalComponent;
    @ViewChild('dateColumn') dateColumn: TemplateRef<any>;

    ngOnInit(){
        this.buildTable();
        this.populateTable();
    }



    buildTable() {
        this.columns = [
            {
                name: 'SID',
                prop: 'sapsid',
                sortable: true,
                sortString: '',
                flexGrow: 1,
                cellTemplate: this.customColumnTemplate,
                headerTemplate: this.sortableColumnTemplate
            },
            {
                name: 'CI Host',
                prop: 'ciHostName',
                sortable: true,
                sortString: '',
                flexGrow: 2,
                cellTemplate: this.customColumnTemplate,
                headerTemplate: this.sortableColumnTemplate
            },
            {
                name: 'App Host',
                prop: 'sapAppHostName',
                sortable: true,
                sortString: '',
                flexGrow: 2,
                headerTemplate: this.sortableColumnTemplate
            },
            {
                name: 'Instance#',
                prop: 'sapAppInstanceNumber',
                sortable: true,
                sortString: '',
                flexGrow: 2,
                headerTemplate: this.sortableColumnTemplate
            },
            {
                name: 'DB Host',
                prop: 'dbHostName',
                sortable: true,
                sortString: '',
                flexGrow: 2,
                headerTemplate: this.sortableColumnTemplate
            },
            {
                name: 'Starts on',
                prop: 'startDateTime',
                sortable: true,
                sortString: '',
                flexGrow: 3,
                headerTemplate: this.sortableColumnTemplate,
                cellTemplate: this.dateColumn
            },
            {
                name: 'Ends on',
                prop: 'stopDateTime',
                sortable: true,
                sortString: '',
                flexGrow: 3,
                headerTemplate: this.sortableColumnTemplate,
                cellTemplate: this.dateColumn
            },
            {
                name: 'Scheduled For',
                prop: 'actionName',
                sortable: true,
                sortString: '',
                flexGrow: 2.7,
                headerTemplate: this.sortableColumnTemplate,
            },
            {
                name: 'Frequency',
                prop: 'frequency',
                sortable: true,
                sortString: '',
                flexGrow: 2,
                headerTemplate: this.sortableColumnTemplate
            },                      
            {
                name: 'Action',
                prop: 'id',
                cellTemplate: this.actionRowTemplate,
                sortable: false,
                flexGrow: 1.3
            }            

        ];
    }

    populateTable() {
        this._schedManagementService.getSchedulingDetails().subscribe(
            response=>{
                this.showSpinner = false;
                this.updateRows(response);
            }, error => {
                this.showSpinner = false;
                this.notificationsService.notify('error', 'Error', "Unexpected error occured while retrieving Scheduling details.");
            }
        )
    }

    deleteSchedule(){
        let id = this.scheduleToDelete;
        this._schedManagementService.deleteSchedulingDetails(id).subscribe(
            result =>{
                this.rows = this.rows.filter(r=> r.id !== id);              
                this.deleteWarningModal.hide();
            },error =>{                
                this.notificationsService.notify('error', 'Error', "Unexpected error occured while deleting schedule.");
            });
    }
}
EN

Stack Overflow用户

发布于 2019-09-25 14:09:34

我可能有点晚了,但是对于仍然存在此问题的人,您只需将组件样式中的css类设置为:

代码语言:javascript
运行
复制
.sort-btn { display: none; }

用按钮隐藏跨度。

至于停用排序,当您在.ts文件中定义列时,将不应该排序的列的可排序属性设置为false:

代码语言:javascript
运行
复制
this.columns = [
        {
            name: 'SID',
            prop: 'sapsid',
            sortable: false, // THIS HERE SET TO FALSE
            sortString: '',
            flexGrow: 1,
            cellTemplate: this.customColumnTemplate,
            headerTemplate: this.sortableColumnTemplate
        }, ...

如果列仍在排序(不应该排序),可以尝试在ngx中将外部排序设置为true:

代码语言:javascript
运行
复制
<ngx-datatable [externalSorting]="true"> 
</ngx-datatable>
票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50208935

复制
相关文章

相似问题

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