SHARE
TWEET

Untitled

a guest Jun 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnDestroy, OnInit, ViewChild, Injectable} from '@angular/core';    
  2. import { DataTableDirective } from 'angular-datatables';    
  3. import {Sort} from '@angular/material';
  4. import { MatTableDataSource, MatSort } from '@angular/material';
  5. import { DataSource } from '@angular/cdk/table';
  6.  
  7. @Component({
  8.    selector: 'app-root',
  9.    templateUrl: 'app.component.html',
  10.    styleUrls: ['app.component.css']
  11. })
  12. export class AppComponent implements OnDestroy, OnInit {
  13.    @ViewChild(DataTableDirective)
  14.    datatableElement: DataTableDirective;
  15.    data =             {
  16.     "transactions":[
  17.         {
  18.         "id": 1,
  19.         "cost":11,
  20.         "quantity":10,
  21.         "productId":1
  22.         },
  23.         {
  24.         "id": 2,
  25.         "cost":12,
  26.         "quantity":100,
  27.         "productId":2
  28.         }
  29.     ]
  30.     }
  31.  
  32.  
  33.    dtOptions: DataTables.Settings = {};
  34.  
  35.    ngOnInit(): void {
  36.  
  37.      $.fn['dataTable'].ext.search.push((settings, data, dataIndex) => {
  38.        const id = parseFloat(data[0]) || 0; // use data for the id column
  39.        return false;
  40.      });
  41.  
  42.      this.dtOptions = {
  43.        ajax: 'data',
  44.        columns: [{
  45.          title: 'ID',
  46.          data: 'id'
  47.        }, {
  48.          title: 'First name',
  49.          data: 'firstName'
  50.        }, {
  51.          title: 'Last name',
  52.          data: 'lastName'
  53.        }]
  54.      };
  55.    }
  56.  
  57.    ngOnDestroy(): void {
  58.      $.fn['dataTable'].ext.search.pop();
  59.    }
  60.  
  61.    filterById(): void {
  62.      this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
  63.        dtInstance.draw();
  64.      });
  65.    }
  66.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top