How to set multiple selection in dropdown in ng2-smart-table?

僤鯓⒐⒋嵵緔 提交于 2020-04-10 02:58:39

问题


In my app, I have load dynamic values in dropdown list of ng2-smart-table. Now I have to enable multiple selection in dropdown in ng2-smart-table.

Note: Multiple selection in dropdown not for checkbox.


回答1:


I think you can try with your own custom editor component. I've added a basic select with a multiple attribute, but you can create a custom component more complex as you prefer.

Pass data to your component with valuePrepareFunction and voila.

settings.ts

private settings = {
 // Previous config ...

 columns: {
  multiple: {
    title: 'Multi select',
    type: 'html',
     editor: {
      type: 'custom',
      valuePrepareFunction: (cell, row) => row,
      component: MultiSelComponent,
     },
  }
 }
}

multiSel.component.html

<select multiple [(ngModel)]="yourModelStore">
  <option *ngFor="let item of myValues" [value]="item.value">{{item.name}}</option>
</select>

multiSel.component.ts

import { Component, Input, OnInit } from '@angular/core';
import { ViewCell } from 'ng2-smart-table';

....

export class MultiSelComponent implements OnInit {

  @Input() value;

  yourModelStore: any; // rendered as this.yourModelStore = ['value', 'value'];

  ngOnInit() {
    this.myValues = this.value;
  }

module.ts

declarations:[
  //others ...

  MultiSelComponent
]
entryComponents: [
  MultiSelComponent
]

**I've edit the answer and added more infos on setting and component.ts




回答2:


 yourField: {
    title: 'Your field title',
    editor: {
      type: 'list',
      config: {
        selectText: 'Select',
        list: [
          { value: '1', title: 'Admin' },
          { value: '2', title: 'Manager' },
        ],
      },
    },
    type: 'number',
  },


来源:https://stackoverflow.com/questions/53729863/how-to-set-multiple-selection-in-dropdown-in-ng2-smart-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!