【问题标题】:Ng2-smart-table : Use drop-downs or date pickers in inline editingNg2-smart-table :在内联编辑中使用下拉菜单或日期选择器
【发布时间】:2020-05-03 17:23:32
【问题描述】:

我正在为 Angular2 寻找更好的表格表示,发现 ng2-smart-table 很好用。但问题是它似乎没有提供一种直接的方式来在线编辑中使用下拉菜单或日期选择器。

有什么方法可以使它成为可能,或者我可以使用哪些替代组件来表示我的 Angular2 应用程序中的表格视图。

【问题讨论】:

标签: angular ng2-smart-table


【解决方案1】:

对于日期选择器:

在设置中[.ts]

settings={
columns:{
// other columns here

dob: {//date of birth
        title: 'yyyy/mm/dd hh:mm',
        type: 'html',
        editor: {
          type: 'custom',
          component: DoBComponent,
        },
   }
}

在 dob.component.html

<owl-date-time autoClose [(ngModel)]="datevalue" dataType="string" 
 (click)="updateValue()">
</owl-date-time>

在 dob.component.ts 中

datevalue: any;
  updateValue(){
    console.log(this.datevalue);
    this.cell.newValue = this.datevalue;
  }
where your DoBComponent extends DefaultEditor

在你的 module.ts 中

     declarations:[
//other compnents here
        DoBComponent
     ]
     entryComponents: [
      DoBComponent
    ]

希望对你有帮助!!!

参考:https://www.npmjs.com/package/ng-pick-datetime, https://akveo.github.io/ng2-smart-table/#/examples/custom-editors-viewers

【讨论】:

    【解决方案2】:

    我在下拉菜单中找到了类似的内容:

    private settings = {
      columns: {
        name: {
          title: 'Name'
        },
        valid: {
          title: 'Valid',
          type: 'html',
          editor: {
            type: 'list',
            config: {
              list: [
                {value: true, title: 'Valid'},
                {value: false, title: 'Not valid'}
              ],
            },
          }
        }, //... more columns
      }
    }
    

    【讨论】:

    • 对不起。我刚看到这个答案。这很棒。想知道你在哪里找到的。日期选择器部分呢?
    • 编辑数据时只需简单的设置下拉菜单。这会很好用。
    【解决方案3】:

    当我使用@ampati-hareesh 的灵魂时,我遇到了三个问题。

    1. “没有用于具有未指定名称属性的表单控件的值访问器”。将 ngDefaultControl 添加到 owl-date-time 即可解决。

    2. “无法读取未定义的属性 'isInSingleMode'”。添加“输入”标签解决了它。

    3. 未分配值。将事件从“clicked”更改为“afterPickerClosed”解决了它。

    我最终的 dob.component.html 看起来像;

        <input placeholder=""
                            [(ngModel)]="dateValue"
                            [owlDateTimeTrigger]="dt1" [owlDateTime]="dt1">
        <owl-date-time [pickerType]="'calendar'" autoClose [(ngModel)]="dateValue" 
             ngDefaultControl dataType="string" 
             (afterPickerClosed)="updateValue()" #dt1>
        </owl-date-time>
    

    【讨论】:

      【解决方案4】:

      public settings = {
          actions: {
            position: 'right',
            //custom: [{ name: 'routeToAPage', title: `<img src="/icon.png">` }]
          },
          columns: {
            ctg_name: {
              title: 'Category',
            },
            ctg_visible: {
              title: 'Visible',
              editor: {
                type: 'list',
                config: {
                  selectText: 'Select',
                  list: [
                    {value: '1', title:'True'},
                    {value: '0', title:'False'}
                  ],
                },
              }
            }
          },
        };

      【讨论】:

        猜你喜欢
        • 2018-05-12
        • 1970-01-01
        • 2017-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多