如何更新 ng2-smart-table 中的占位符文本?

khu*_*boo 5 placeholder ng2-smart-table angular

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

<ng2-smart-table [settings]="setting" [source]="dataSource"></ng2-smart-table>
Run Code Online (Sandbox Code Playgroud)

在 .ts 文件中。

add: {
  confirmCreate: false
},
columns: {
   id: {
    title: 'ID',
    filter: true        
  },
  name: {
    title: 'First Name',
    filter: true                
  },
}
Run Code Online (Sandbox Code Playgroud)

Par*_*mar 4

更改 ng2 智能表的占位符

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

在您的 var 列中添加以下行,

this.placeholder = '';
Run Code Online (Sandbox Code Playgroud)

它看起来像

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();
    }
Run Code Online (Sandbox Code Playgroud)

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

它看起来像这样

 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'];
    };
Run Code Online (Sandbox Code Playgroud)

步骤 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  ",
    }),
Run Code Online (Sandbox Code Playgroud)

到:

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  ",
        }),
Run Code Online (Sandbox Code Playgroud)

第 4 步:转到您的 component.ts 并在您的列详细信息中添加以下行,如下所示 -->

  columns: {
        ExamID: {
          title: this.translate.get("table.ExamID")["value"],
          **placeholder:"your place holder",**
          type: "string"
        },
Run Code Online (Sandbox Code Playgroud)

你准备好了