Подтвердить что ты не робот

Добавить пользовательскую кнопку в столбец действий в ng2-smart-table angular 2

в ng2-smart-table angular 2 Я хочу добавить новую кнопку в столбец действий и щелкнув по этой кнопке, она перейдет на другую страницу это кнопки добавления, редактирования и удаления, но я попытался сделать новую кнопку таким образом, но она не работает.

settings = {

    add: {
      addButtonContent: '<i  class="ion-ios-plus-outline"></i>',
      createButtonContent: '<i class="ion-checkmark" ></i>',
      cancelButtonContent: '<i class="ion-close"></i>',
      confirmCreate: true,

    },
    edit: {
      editButtonContent: '<i class="ion-edit"></i>',
      saveButtonContent: '<i class="ion-checkmark"></i>',
      cancelButtonContent: '<i class="ion-close"></i>',
          confirmSave: true
    },
    delete: {
      deleteButtonContent: '<i class="ion-trash-a"></i>',
      confirmDelete: true
    }, 

как я могу добавить кнопку, я искал в документации таблицы ng2-smart и я не могу найти что-либо, связанное с этим https://akveo.github.io/ng2-smart-table/documentation

4b9b3361

Ответ 1

Попробуйте:

В настройках столбцов добавьте один столбец "Действия":

  Actions: //or something
  {
    title:'Detail',
    type:'html',
    valuePrepareFunction:(cell,row)=>{
      return `<a title="See Detail Product "href="Your api key or something/${row.Id}"> <i class="ion-edit"></i></a>`
    },
    filter:false       
  },
  Id: { //this Id to use in ${row.Id}
    title: 'ID',
    type: 'number'
  },

Ответ 2

В вашем файле настроек поместите следующие

actions: {
  edit: false, //as an example
  custom: [{ name: 'routeToAPage', title: `<img src="/icon.png">` }]
}

Теперь у вас есть пользовательская кнопка routeToAPage с img.

Затем в тэге ng2-smart-table

<ng2-smart-table [settings]="settings" [source]="dataSource" (custom)="route($event)"></ng2-smart-table>

Затем вы можете создать функцию маршрута и выполнить то, что ему нужно.

Ответ 3

У меня была та же проблема, и я нашел решение с помощью настраиваемого действия на основе следующего примера: basic-example-custom-actions.component

настройки:

actions: {
  add: false,
  edit: false,
  delete: false,
  custom: [{ name: 'ourCustomAction', title: '<i class="nb-compose"></i>' }],
  position: 'right'
},

В шаблоне: мы определяем функцию, вызываемую нашим действием

<ng2-smart-table #ourTable [settings]="settings" [source]="source"
    (custom)="onCustomAction($event)">

Нам нужен роутер:

import {Router} from '@angular/router';
...
constructor(private router: Router) {}

Затем мы можем перенаправить на другую страницу:

onCustomAction(event) {
  // alert('Custom event '${event.action}' fired on row №: ${event.data.id}');
  this.router.navigate(['pages/ourPage']);
}

То же самое можно применить, когда пользователь нажимает на строку:

(userRowSelect)="onCustomAction($event)"

Ответ 4

Если вы все еще ищете решение, я столкнулся с той же проблемой и не смог ее исправить.

Возвращение к выпуску 1.1.0 (из вас package.json) сделал это для меня! Я также обнаружил, что тег buttonContent отлично работает для редактирования и удаления, но не для добавления.

Надеюсь, эта ошибка скоро будет исправлена.

Ответ 5

На html Template вы можете подписаться на редактирование события delete:

<ng2-smart-table [settings]="settings" [source]="source" (edit)="onEdit($event)" (delete)="onDelete($event)"></ng2-smart-table>

onEdit onDelete теперь являются вашими пользовательскими функциями, чтобы что-то изменить.

Надеюсь, это поможет!

Ответ 6

В моем списке компонентов

actions: {
      columnTitle: 'Actions',
      add: false,
      edit: false,
      delete: true,
      custom: [
      { name: 'viewrecord', title: '<i class="fa fa-eye"></i>'},
      { name: 'editrecord', title: '&nbsp;&nbsp;<i class="fa  fa-pencil"></i>' }
    ],
      position: 'right'
    },

Тогда в шаблоне

  <ng2-smart-table class="table table-hover" [settings]="settings" [source]="dataSet"
   (deleteConfirm)="onDeleteConfirm($event)"  (custom)="onCustomAction($event)">
  </ng2-smart-table>

Эта функция помогла мне решить, какое пользовательское действие выполнить.

onCustomAction(event) {
      switch ( event.action) {
        case 'viewrecord':
          this.viewRecord(event.data);
          break;
       case 'editrecord':
          this.editRecord(event.data);
      }
    }

public editRecord(formData: any) {
      this.modalRef = this.modalService.open(AddProfileComponent);
      this.modalRef.componentInstance.formData = formData;
      this.modalRef.result.then((result) => {
        if (result === 'success') {
          this.loadData();
        }
      }, (reason) => {
      });
    }
    public viewRecord(formData: any) {
      this.modalRef = this.modalService.open(ViewProfileComponent);
      this.modalRef.componentInstance.formData = formData;
      this.modalRef.result.then((result) => {
        if (result === 'success') {
          this.loadData();
        }
      }, (reason) => {
      });
    }