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

标签 angular placeholder ng2-smart-table

我正在使用 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 并更改以下行 --> 来自

   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/

相关文章:

html - HTML 中的占位符与数据占位符

asp.net - 如何将占位符属性与 Html.EditorFor 一起使用?

使用ng2-smart表的回调 'this'函数时,Angular 4, 'onComponentInitFunction'未定义

javascript - Angular 2 和 AmCharts

javascript - 从嵌套回调函数中返回 Observable

angular - 如何避免 Observable 中超出最大调用堆栈大小?

jquery - 占位符和 ie9

javascript - ng2 智能表格复选框不会在所有页面上持久存在

angular - 如何使用 Angular 6 中的智能表将数据更新到另一个页面

javascript - 如果指定为 `@ViewChildren` 的读取参数,ViewContainerRef 会引用哪些组件 View