首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ng2-smart-table:如何在编辑模式下使用当前值预先选择下拉列表

ng2-smart-table是一个基于Angular的开源表格插件,用于快速构建数据表格界面。在编辑模式下使用当前值预先选择下拉列表,可以通过自定义编辑器来实现。

首先,需要在ng2-smart-table的配置中定义一个自定义的编辑器。在编辑器中,可以使用ng-select或其他下拉列表组件来实现预先选择下拉列表的功能。

以下是一个示例配置:

代码语言:txt
复制
import { Component } from '@angular/core';
import { LocalDataSource } from 'ng2-smart-table';

@Component({
  template: `
    <ng-select [items]="options" [ngModel]="cell.newValue" (ngModelChange)="onSelect($event)">
    </ng-select>
  `,
})
export class CustomEditorComponent {
  cell: any;
  options: any[] = [
    { value: 'option1', title: 'Option 1' },
    { value: 'option2', title: 'Option 2' },
    { value: 'option3', title: 'Option 3' },
  ];

  constructor() {}

  onSelect(value: any) {
    this.cell.newValue = value;
  }
}

@Component({
  selector: 'app-table',
  template: `
    <ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>
  `,
})
export class TableComponent {
  data: LocalDataSource;
  settings: any = {
    columns: {
      columnName: {
        title: 'Column Name',
        editor: {
          type: 'custom',
          component: CustomEditorComponent,
        },
      },
    },
  };

  constructor() {
    this.data = new LocalDataSource(data);
  }
}

在上述示例中,我们定义了一个CustomEditorComponent作为自定义编辑器,使用ng-select组件来展示下拉列表。在编辑器中,我们通过ngModel绑定当前值,并在选择新值时更新newValue属性。

然后,在ng2-smart-table的配置中,将编辑器类型设置为'custom',并指定CustomEditorComponent作为编辑器组件。

这样,在表格的编辑模式下,当用户点击编辑按钮时,会显示预先选择下拉列表,并且当前值会被预先选中。

请注意,以上示例仅为演示目的,实际使用时需要根据具体情况进行适当修改。

推荐的腾讯云相关产品:腾讯云云服务器(CVM)和腾讯云数据库(TencentDB)。您可以通过以下链接了解更多信息:

相关搜索:我的下拉列表在mvc的编辑模式下无法获得值如何在编辑模式下选择依赖下拉列表Selenium无法在无头模式下选择下拉列表中的值在模式下编辑表单时,如何从从属下拉列表中获取之前选择的选项?如何使用模式编码器4在编辑模式下获取“selected”选项值在fulleditmode/designmode模式下,如何使用Javascript/JQuery引用当前选择的<div>?如何使用Javascript在Orbeon Forms中设置下拉列表的选定值?SwiftUI -在编辑模式下,但不使用onDelete时,如何避免列表中的行缩进?(代码/视频附件)在交互式报表中使用APEX_ITEM创建下拉列表时,如何调整APEX值列表?如何使用下拉列表中的值在kendo网格上设置初始过滤器Django Forms:如何使用现有模型中的值在表单中创建简单的下拉列表如何使用chrome中的<Option Value="">在默认情况下选择下拉列表中的所有选项?如何在下拉列表中使用angular路由器?在特定条件下如何进行重定向?在Vim模式下使用atom编辑器时,在自动完成给出的列表中选择下一个选项的按键是什么?如何使用CodeIgniter中的下拉列表在HTML表中显示过滤后的数据库值?在使用tablesorter.filterformatter小部件时,如何以编程方式从select2下拉列表中进行选择?Syncfusion MVC Grid:在向网格添加行时,如何使用硬编码值呈现特定单元格中的下拉列表如何让tkinter combobox循环在类中工作,使用列表作为默认值,并在下拉菜单中使用一个字典?在python中,如何在不使用内置函数(仅使用循环)的情况下将相同长度的两个列表中的值相减?
相关搜索:
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券