Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom css in ng2-smart-table

Tags:

angular

I am using angular 2 with ng2-smart-table.

Here is my code.

settings = {
    mode:"external",
    actions:{add:false,position:'right',custom: [{ name: 'View', title: `<i class="fa fa-eye" aria-hidden="true"></i>` }]},
    edit: {
      editButtonContent: '<i class="fa fa-pencil-square" aria-hidden="true"></i>',
      saveButtonContent: '<i class="ion-checkmark"></i>',
      cancelButtonContent:'<i class="ion-close"></i>',
    },
    delete: {
      deleteButtonContent: '<i class="fa fa-trash" aria-hidden="true"></i>',
      confirmDelete: true
    },
    columns: {
       Check:{
        title: "Check",
        type: 'html',
        },
        filter: false
       },
       orderby:{
        title: "Name",
        filter: true
       },
       purchased:{
        title: "Purchased",
        type: 'html',
        },
        filter: false
       },
       shipto:{
        title: "Ship To",
        filter: true
       },
       date:{
        title: "Date",
        filter: true
       },
       total:{
        title: "Total Amount",
        filter: true
       },
       status: {
        title: "Status",
        filter: true
      }
    }
  };

I added custom view icon in table. It works, but how to add custom css in ng2-smart-table?

I tried this

 ng2-smart-table thead > tr > th { background-color: blue; }

But it doesn't work.

like image 415
sarankani Avatar asked Oct 26 '25 13:10

sarankani


2 Answers

Try this making using of host in order to style the components as view encapsulation is not set.

:host /deep/ ng2-smart-table thead > tr > th  { 
        background-color:blue;  
}

More info on host and hostcontext link

like image 169
Rahul Singh Avatar answered Oct 28 '25 03:10

Rahul Singh


use below configuration in the setting object

attr: {
        class: 'table table-bordered'
      },

and

 :host /deep/ ng2-smart-table { 
    font-size: 16px; 
}

Example :

settings = {
  columns: {
    id: {
      title: 'ID'
    },
    name: {
      title: 'Full Name'
    },
    username: {
      title: 'User Name'
    },
    email: {
      title: 'Email'
    }
  },
attr: {
        class: 'table table-bordered'
      }
};
like image 41
Ankit Pant Avatar answered Oct 28 '25 04:10

Ankit Pant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!