我正在使用 ng2-smart-tableangular 6 应用程序中显示数据。我已启用过滤器功能。现在我想将默认 search 设置为所有 columns 占位符中的文本。我已经搜索了很多。但我无法更改过滤器的占位符。

<ng2-smart-table [settings]="setting" [source]="dataSource"></ng2-smart-table>

在 .ts 文件中。
add: {
  confirmCreate: false
},
columns: {
   id: {
    title: 'ID',
    filter: true
  },
  name: {
    title: 'First Name',
    filter: true
  },
}

最佳答案

更改 ng2 智能表的占位符

第 1 步:转到-->
node_modules\ng2-smart-table\lib\data-set\column.js

在 var 列中添加以下行,

this.placeholder = '';

它看起来像
var Column = (function () {
    function Column(id, settings, dataSet) {
        this.id = id;
        this.settings = settings;
        this.dataSet = dataSet;
        this.title = '';
        this.placeholder = '';
        this.type = '';
        this.class = '';
        this.isSortable = false;
        this.isEditable = true;
        this.isFilterable = false;
        this.sortDirection = '';
        this.defaultSortDirection = '';
        this.editor = { type: '', config: {}, component: null };
        this.filter = { type: '', config: {} };
        this.renderComponent = null;
        this.process();
    }

第 2 步:在同一个文件上 -->
在Column.prototype.process = function(){}中添加this.placeholder = this.settings['placeholder'];

它看起来像这样
 Column.prototype.process = function () {
        this.title = this.settings['title'];
        this.placeholder = this.settings['placeholder'];
        this.class = this.settings['class'];
        this.type = this.prepareType();
        this.editor = this.settings['editor'];
        this.filter = this.settings['filter'];
        this.renderComponent = this.settings['renderComponent'];
        this.isFilterable = typeof this.settings['filter'] === 'undefined' ? true : !!this.settings['filter'];
        this.defaultSortDirection = ['asc', 'desc']
            .indexOf(this.settings['sortDirection']) !== -1 ? this.settings['sortDirection'] : '';
        this.isSortable = typeof this.settings['sort'] === 'undefined' ? true : !!this.settings['sort'];
        this.isEditable = typeof this.settings['editable'] === 'undefined' ? true : !!this.settings['editable'];
        this.sortDirection = this.prepareSortDirection();
        this.compareFunction = this.settings['compareFunction'];
        this.valuePrepareFunction = this.settings['valuePrepareFunction'];
        this.filterFunction = this.settings['filterFunction'];
    };

第 3 步:转到 node_modules\ng2-smart-table\components\filter\filter-types\input-filter.component.js 并更改以下行 --> from
   Component({
        selector: 'input-filter',
        template: "\n    <input [(ngModel)]=\"query\"\n           [ngClass]=\"inputClass\"\n           [formControl]=\"inputControl\"\n           class=\"form-control\"\n           type=\"text\"\n           placeholder=\" {{ column.title}}\" />\n  ",
    }),

至:
Component({
            selector: 'input-filter',
            template: "\n    <input [(ngModel)]=\"query\"\n           [ngClass]=\"inputClass\"\n           [formControl]=\"inputControl\"\n           class=\"form-control\"\n           type=\"text\"\n           placeholder=\" {{ column.placeholder }}\" />\n  ",
        }),

第 4 步:转到您的 component.ts 并在您的列详细信息中添加以下行,如下所示 -->
  columns: {
        ExamID: {
          title: this.translate.get("table.ExamID")["value"],
          **placeholder:"your place holder",**
          type: "string"
        },

你准备好了

关于angular - 如何更新 ng2-smart-table 中的占位符文本?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52232701/

10-11 14:46