简体   繁体   English

ng2-smart-table 中的日期未显示

[英]date in ng2-smart-table is not displaying

I'm trying to add and display my data using smart table using angular 10 one of the table columns is the date I installed mydatepicker I made a component called calendar我正在尝试使用智能表添加和显示我的数据 angular 10 其中一个表列是我安装 mydatepicker 的日期 我制作了一个名为calendar的组件

here's calendar.ts这是calendar.ts

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

@Component({
  selector: 'app-calendar',
  templateUrl: './calendar.component.html',
  styleUrls: ['./calendar.component.scss']
})
export class CalendarComponent {

  public startDateOptions: IMyDpOptions = {
    dateFormat: 'yyyy/mm/dd',
    editableDateField: false,
    openSelectorOnInputClick: true,
    firstDayOfWeek: 'su',
    satHighlight: true,
    selectionTxtFontSize: '13px',
    dayLabels: {
      su: 'أح',
      mo: 'اث',
      tu: 'ث',
      we: 'أر',
      th: 'خ',
      fr: 'ج',
      sa: 'س',
    },
    monthLabels: {
      1: 'جانفي',
      2: 'فيفري',
      3: 'مارس',
      4: 'أفريل',
      5: 'ماي',
      6: 'جوان',
      7: 'جويلية',
      8: 'أوت',
      9: 'سبتمبر',
      10: 'أكتوبر',
      11: 'نوفمبر',
      12: 'ديسمبر',
    },
    height: '26px',
    todayBtnTxt: "اليوم",
    // disableSince: this.getCurrentDate()
  };
  public endDateOptions: IMyDpOptions = this.startDateOptions;


}

@Component({
  template: {{value | date:'short'}} ,
})
export class CalendarRenderComponent implements  ViewCell,OnInit {
  @Input() value: string;
  @Input() rowData: any;

  constructor() { }

  ngOnInit() { }
  

}

and here's how I called it in smart-table.ts这是我在smart-table.ts中的称呼

import { Component } from '@angular/core';
import { IMyDpOptions, IMyDateModel } from 'mydatepicker';
import { CalendarComponent, CalendarRenderComponent } from './calendar/calendar.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'grp';

  settings = {
    columns: {
      id: {
        title: 'id'
      },
      name: {
        title: 'name'
      },
      username: {
        title: 'username'
      },
      email: {
        title: 'email'
      },
      birthday: {
        title: 'Birthday',
        type: 'custom',
        renderComponent: CalendarRenderComponent,
        width: '250px',
        filter: false,
        sortDirection: 'desc',
        editor: {
          type: 'custom',
          component: CalendarComponent,
        },
      },
    },
    delete: {
      deleteButtonContent: '<i class="fa fa-trash" style="font-size:32px"></i>',
      saveButtonContent: 'save',
      cancelButtonContent: 'cancel',

    },
    add: {
      addButtonContent:'<i class="fa fa-plus" style="background-color: green;"></i>',
      createButtonContent: '<i class="fa fa-check"></i>',
      cancelButtonContent: '<i class="fa fa-times"></i>',
    },
    edit: {
      editButtonContent:'<i class="fa fa-pencil" style="font-size:32px"></i>',
      saveButtonContent:'<i class="fa fa-check"></i>',
      cancelButtonContent: '<i class="fa fa-times"></i>',
    },
  };
  data = [
    {
      id: 1,
      name: "test Graham",
      username: "Bret",
      email: "test@april.com",
      birthday: "2019-08-14T00:00:00"
    },
    {
      id: 2,
      name: "test Howell",
      username: "test",
      email: "test@gmail.tv",
      birthday: "2019-08-14T00:45:51"
    },
    {
      id: 11,
      name: "testDuBuque",
      username: "test.Stanton",
      email: "test@test.biz",
      birthday: "2019-08-14T00:45:51"
    }
  ]; 

  
}

I have no problem with displaying the calendar and choosing the date when I click add new but when I click create all the data is displayed fine except for the date, it's blank.当我单击“添加新”时显示日历和选择日期没有问题,但是当我单击“创建”时,除日期外,所有数据都显示正常,它是空白的。 in the console, I got ERROR Error: The pipe 'date' could not be found!在控制台中,我收到ERROR Error: The pipe 'date' could not be found!

I would really appreciate the help我真的很感激你的帮助

To just show the date value you should add something like this to you column setting:要仅显示日期值,您应该在列设置中添加类似这样的内容:

valuePrepareFunction: (value: string) => {
    return new Date(value).toLocaleDateString();
},

This prepares the value to be shown when not in editor mode.这准备在不处于编辑器模式时显示的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM