Top

Tables


# First Name Last Name Username Role Country
1 Alexander Orton @mdorton Admin USA
2 John Deo Deo @johndeo User USA
3 Randy Orton the Bird @twitter admin UK
4 Randy Mark Ottandy @mdothe user AUS
5 Ram Jacob Thornton @twitter admin IND
<div class="card">
  <div class="table-responsive theme-scrollbar">
    <table class="table">
      <thead>
        <tr class="border-bottom-primary">
          <th scope="col">Id</th>
          <th scope="col">First Name</th>
          <th scope="col">Last Name</th>
          <th scope="col">Username</th>
          <th scope="col">Designation</th>
          <th scope="col">Company</th>
          <th scope="col">Language</th>
          <th scope="col">Country</th>
        </tr>
      </thead>
      <tbody>
        <ng-container *ngFor="let data of tableData">
          <tr class="border-bottom-{{ data.borderColor }}">
            <th scope="row">{{ data.id }}</th>
            <td> <img class="img-30 me-2" src="{{ data.img }}" alt="profile">{{ data.fname }}</td>
            <td>{{ data.lname }}</td>
            <td>{{ data.username }}</td>
            <td>{{ data.designation }}</td>
            <td>{{ data.company }}</td>
            <td> <span class="badge badge-light-{{ data.badgeColor }}">{{ data.language }}</span></td>
            <td>{{ data.country }}</td>
          </tr>
        </ng-container>
      </tbody>
    </table>
  </div>
</div>
import { Component } from '@angular/core';
import { Component } from '@angular/core';
import * as Data from '../../../../../shared/data/data/forms/bootstrap-table'


@Component({
    selector: 'app-table-bottom-border',
    templateUrl: './table-bottom-border.html',
    styleUrls: ['./table-bottom-border.scss'],
    import:[]
    
})
export class TableBottomBorder {

  public tableData = Data.commonTableData;

}

export const commonTableData: commonTable[] = [
  {
      id: 1,
      img: '/assets/images/user/1.jpg',
      fname: 'Ram Jacob',
      lname: 'Wolfe',
      username: 'RamJacob@twitter',
      designation: 'Developer',
      company: 'Apple Inc.',
      language: 'Php',
      badgeColor: 'danger',
      country: 'IND',
      borderColor: 'secondary',
      creditVolume: '3500.00',
  },
  {
      id: 2,
      img: '/assets/images/user/2.jpg',
      fname: 'John Deo',
      lname: 'Gummer',
      username: 'JohnDeo@twitter',
      designation: 'Designer',
      company: 'Hewlett packard',
      language: 'Html',
      badgeColor: 'primary',
      country: 'US',
      borderColor: 'success',
      creditVolume: '2400.00',
  },
]

You have to change only table sizing class.you can use table-*(sm,lg,xl,xs) class

# First Last Handle
1 Mark Otto @mdo
2 Jacob Thornton @fat
3 Larry the Bird @twitter
<div class="card">
  <div class="card-block row">
      <div class="col-sm-12 col-lg-12 col-xl-12">
          <div class="table-responsive theme-scrollbar">

              <table class="table table-lg">
                  <thead>
                      <tr>
                          <th scope="col">Id</th>
                          <th scope="col">Employee Name</th>
                          <th scope="col">Date</th>
                          <th scope="col">Status</th>
                          <th scope="col">Hours</th>
                          <th scope="col">Performance</th>
                      </tr>
                  </thead>
                  <tbody>
                      <tr *ngFor="let data of sizingTableData">
                          <th scope="row">{{ data.id }}</th>
                          <td>{{ data.employeeName }}</td>
                          <td>{{ data.date }}</td>
                          <td class="font-{{ data.statusColor }}">{{ data.status }}</td>
                          <td>{{ data.hours }}</td>
                          <td>{{ data.performance }}</td>
                      </tr>
                  </tbody>
              </table>
          </div>
      </div>
  </div>
</div>
import { Component } from '@angular/core';
import * as Data from '../../../../../shared/data/data/forms/bootstrap-table'

@Component({
    selector: 'app-sizing-table',
    templateUrl: './sizing-table.html',
    styleUrls: ['./sizing-table.scss'],
    imports: []
})

export class SizingTable {

  public sizingTableData = Data.sizingTableData;

}
export const sizingTableData= [
  {
      id: 1,
      employeeName: 'Mark Jecno',
      date: '22/08/2025',
      status: 'On leave',
      statusColor: 'danger',
      hours: '0',
      performance: '29/30',
  },
  {
      id: 2,
      employeeName: 'Elana Robbert',
      date: '21/08/2025',
      status: 'Present',
      statusColor: 'success',
      hours: '10',
      performance: '30/30',
  },
  {
      id: 3,
      employeeName: 'John Deo',
      date: '18/08/2025',
      status: 'On leave',
      statusColor: 'danger',
      hours: '8',
      performance: '28/30',
  },
]
Name Position Office Age Start date Salary
Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800
Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
<table class="table display" id="selling-product" style="width:100%">
  <thead>
      <tr>
          <th>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="">
                <label class="form-check-label" for="flexCheckDefault"></label>
              </div>
          </th>
          <th scope="col">#UID</th>
          <th scope="col" sortable="product" (sort)="onSort($event)" style="cursor: pointer;">Product</th>
          <th scope="col" sortable="category" (sort)="onSort($event)" style="cursor: pointer;">Catagory</th>
          <th scope="col" sortable="brand" (sort)="onSort($event)" style="cursor: pointer;">Brand</th>
          <th scope="col" sortable="price" (sort)="onSort($event)" style="cursor: pointer;">Price </th>
          <th scope="col" sortable="stock" (sort)="onSort($event)" style="cursor: pointer;">Stock</th>
          <th scope="col" sortable="rating" (sort)="onSort($event)" style="cursor: pointer;">Rating</th>
          <th scope="col" sortable="order" (sort)="onSort($event)" style="cursor: pointer;">Order</th>
          <th scope="col" sortable="sales" (sort)="onSort($event)" style="cursor: pointer;">Sales</th>
          <th>Action</th>
      </tr>
  </thead>
  <tbody>
      <tr *ngFor="let data of selling$ | async; let i=index">
          <td>
              <div class="form-check">
                <input class="form-check-input" id="flexCheckDefault" type="checkbox" value="">
                <label class="form-check-label" for="flexCheckDefault"></label>
              </div>
          </td>
          <td><b>#{{data.id}}</b></td>
          <td>
              <div class="d-flex align-items-center">
                  <div class="flex-shrink-0"><img class="img-50" src={{data.img}}>
                  </div>
                  <div class="flex-grow-1 ms-2"><a
                          [routerLink]="['/ecommerce/product-page']">
                          <h5>{{data.product}}</h5>
                      </a></div>
              </div>
          </td>
          <td><b>{{data.category}}</b></td>
          <td><b>{{data.brand}}</b></td>
          <td><b>${{data.price | number : '1.2-2'}}</b></td>
          <td><b>{{data.stock}}</b></td>
          <td><b>
                  <p><i class="fa fa-star font-warning"></i>{{data.rating}}</p>
              </b></td>
          <td><b>{{data.order}}</b></td>
          <td><b>{{data.sales}}</b></td>
          <td class="text-center">
              <span class="edit-option">
                  <a href="javascript:void(0)">
                      <app-feather-icons [icon]="'edit'"></app-feather-icons>
                      <!-- <i data-feather="edit"></i> -->
                  </a>
              </span>
              <span class="delete-option">
                  <a href="javascript:void(0)" (click)="removeItem(data.id)">
                      <i class="remove" data-feather="trash-2"></i>
                  </a>
              </span>
          </td>
      </tr>
  </tbody>
</table>
To use datatable you have to add the following code in ts file
import { Component, QueryList, ViewChildren } from '@angular/core';
import { Observable } from 'rxjs';
import { sellingProduct } from '../../../../shared/data/data/default-dashboard/best-selling-product';
import { SortEvent, SortableDirective } from '../../../../shared/directive/sortable.directive';
import { TablesService } from '../../../../shared/services/tables/tables.service';
import { FeatherIcons } from '../../../../shared/component/feather-icons/feather-icons';
import { RouterLink } from '@angular/router';
import {  AsyncPipe, DecimalPipe } from '@angular/common';

@Component({
  selector: 'app-common-data-table',
  templateUrl: './common-data-table.html',
  styleUrls: ['./common-data-table.scss'],
  imports: [SortableDirective,  RouterLink, FeatherIcons, AsyncPipe, DecimalPipe]
})

export class CommonDataTable {

  public isShow : boolean = false;
  public selling$ : Observable;
  public total$ : Observable;

  @ViewChildren(SortableDirective) headers!: QueryList;

  constructor(public service : TablesService) {
    this.selling$ = service.selling$;
    this.total$ = service.total$;
  }

  onSort({ column, direction }: SortEvent){
    this.headers.forEach((header) => {
      if(header.sortable !== column) {
        header.direction = '';
      }
    });
    this.service.sortColumn = column;
    this.service.sortDirection = direction;
  }

  removeItem(id: number){
    this.selling$.subscribe((data: sellingProduct[])=> {      
      data.map((elem: sellingProduct,i: number)=>{elem.id == id && data.splice(i,1)})
    })
  }
}
To use datatable you have to add the following service file
import { Injectable, PipeTransform } from '@angular/core';
import { BehaviorSubject, Observable, Subject, debounceTime, delay, of, pipe, switchMap, tap } from 'rxjs';
import { DecimalPipe } from '@angular/common';
import { SortColumn, SortDirection } from '../../directive/sortable.directive';
import { BestSellingProduct, sellingProduct } from '../../data/data/default-dashboard/best-selling-product';

interface SearchResult {
	selling: sellingProduct[];
	total: number;
}

interface State {
	page: number;
	pageSize: number;
	searchTerm: string;
	sortColumn: SortColumn;
	sortDirection: SortDirection;
}

const compare = (v1: string | number, v2: string | number) => (v1 < v2 ? -1 : v1 > v2 ? 1 : 0);

function sort(selling: sellingProduct[], column: SortColumn, direction: string): sellingProduct[] {
	if (direction === '' || column === '') {
		return selling;
	} else {
		return [...selling].sort((a : any, b : any) => {
			const res = compare(a[column], b[column]);
			return direction === 'asc' ? res : -res;
		});
	}
}

function matches(sellingData: sellingProduct, term: string, pipe: PipeTransform) {
	return (
		sellingData.product.toLowerCase().includes(term.toLowerCase()) ||
    sellingData.category.toLowerCase().includes(term.toLowerCase()) ||
    sellingData.brand.toLowerCase().includes(term.toLowerCase()) ||
    pipe.transform(sellingData.price).includes(term) ||
    pipe.transform(sellingData.stock).includes(term) ||
    pipe.transform(sellingData.order).includes(term) ||
    pipe.transform(sellingData.sales).includes(term)
	);
}

@Injectable({
  providedIn: 'root'
})

export class TablesService {

    private _loading$ = new BehaviorSubject(true);
    private _search$ = new Subject();
    private _selling$ = new BehaviorSubject([]);
    private _total$ = new BehaviorSubject(0);
  
    private _state: State = {
      page: 1,
      pageSize: 4,
      searchTerm: '',
      sortColumn: '',
      sortDirection: '',
    };

    constructor(private pipe: DecimalPipe) {
      this._search$
        .pipe(
          tap(() => this._loading$.next(true)),
          debounceTime(200),
          switchMap(() => this._search()),
          delay(200),
          tap(() => this._loading$.next(false)),
        )
        .subscribe((result) => {
          this._selling$.next(result.selling);
          this._total$.next(result.total);
        });
  
      this._search$.next();
    }
  
    get selling$() {
      return this._selling$.asObservable();
    }
    get total$() {
      return this._total$.asObservable();
    }
    get loading$() {
      return this._loading$.asObservable();
    }
    get page() {
      return this._state.page;
    }
    get pageSize() {
      return this._state.pageSize;
    }
    get searchTerm() {
      return this._state.searchTerm;
    }
  
    set page(page: number) {
      this._set({ page });
    }
    set pageSize(pageSize: number) {
      this._set({ pageSize });
    }
    set searchTerm(searchTerm: string) {
      this._set({ searchTerm });
    }
    set sortColumn(sortColumn: SortColumn) {
      this._set({ sortColumn });
    }
    set sortDirection(sortDirection: SortDirection) {
      this._set({ sortDirection });
    }
  
    private _set(patch: Partial) {
      Object.assign(this._state, patch);
      this._search$.next();
    }

    private _search(): Observable {
      const { sortColumn, sortDirection, pageSize, page, searchTerm } = this._state;
  
      // 1. sort
      let selling = sort(BestSellingProduct, sortColumn, sortDirection);
  
      // 2. filter
      selling = selling.filter((sellingProduct) => matches(sellingProduct, searchTerm, this.pipe));
      const total = selling.length;
  
      // 3. paginate
      selling = selling.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize);
      return of({ selling, total });
    }
}
To use datatable you have to add the following code in directive
import { Directive, EventEmitter, Input, Output } from '@angular/core';
import { sellingProduct } from '../data/data/default-dashboard/best-selling-product';

export type SortColumn = keyof sellingProduct | '';
export type SortDirection = 'asc' | 'desc' | '';
const rotate: { [key: string]: SortDirection } = { asc: 'desc', desc: '', '': 'asc' };

export interface SortEvent {
	column: SortColumn;
	direction: SortDirection;
}


@Directive({
  selector: 'th[sortable]',
  host: {
		'[class.asc]': 'direction === "asc"',
		'[class.desc]': 'direction === "desc"',
		'(click)': 'rotate()',
	},
})

export class SortableDirective {

  @Input() sortable: SortColumn = '';
	@Input() direction: SortDirection = '';
	@Output() sort = new EventEmitter();

	rotate() {
		this.direction = rotate[this.direction];
		this.sort.emit({ column: this.sortable, direction: this.direction });
	}
  constructor() { }

}