1.0.2 • Published 6 years ago

ng-smarter-table v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

NgSmarterTable

An Angular 5 smart table that handles filtering, sorting, inline editing, deleting, and more!

Installation

For now, this table only supports bootstrap.

NPM

  npm install ng-smarter-table
  • Make sure you have the bootstrap css, along with fontawesome installed in your project. If not, add the following css links to your index.html in the root of your project.

    As per the Boostrap Docs:

    As per the FontAwesome Docs:

    <!-- index.html -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" 
    integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
     crossorigin="anonymous">
    <!-- fontawesome -->
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  • Add SmarterTableModule to your Module file:

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        SmarterTableModule
      ],
      providers: [],
      bootstrap: [AppComponent]

Usage

  • Add smarter table to your html component, specifying your rows and columns, at least:

      <smarter-table
            [columns]="columns"
            [rows]="rows">
      </smarter-table>

    Example on columns and rows:

    columns = [
        {type: 'text', visible: true, name: 'First Name', binder: 'fname' },
        {type: 'text', visible: true, name: 'Last Name', binder: 'lname' },
        {type: 'text', visible: true, name: 'Date of birth', binder: 'dob' },
        {type: 'number', name: 'numbers', visible: true, binder: 'nums' },
        {type: 'text', name: 'Gender', visible: true, binder: 'gender' },
      ]
    
    rows = [
      {fname: "Connor", lname: 'Makhlouta', dob: "24/5/1996", nums: 414, gender: "male"},
      {fname: "George", lname: 'Rattel', dob: '14/5/1992', nums: 4414, gender: "male"},
      {fname: "Sabrina", lname: 'Azar', dob: '16/1/1997', nums: 4414, gender: "female"},
    ]

    Column

    AttributeValuesDescription
    type'text'/'number'Type of the column to be stored, used in identifying for sort and filter
    nameanyName to be shown on column
    binderanyProperty name in row for this column to be bound to

    Additional Features

    Smarter Table supports filtering, sorting, pagination, inline editing, and exporting to excel.

    • Sorting: Depending on the type given in the column, the sort will execute, whether a number or string

    • Filtering: Depending on the type given in the column, a filter can be used, whether number or string

    • Pagination: Depending on a page length specified, different page sizes can be given

    • Export to Excel: Speaks for itslef

    • Inline editing: If enabled, user can edit a record inline, while specifying a function in order to be run on save, in case of updating an external source. User is then urged to refresh data source

    • Filtering by column: User can set which columns are to be visible and which are not to be

    Inputs

    AttributeTypeDefaultDescription
    filterBooleanfalseWhether or not to enable filter
    can_deleteBooleanfalseWhether or not to show a delete button
    can_editBooleanfalseWhether or not to show a edit button
    inline_editBooleanfalseWhether or not a user should be able to inline edit on the table
    inline_edit_grouparray[]Description of inline edit types to be used. Dropdown/text
    paginationBooleanfalseWhether or not to enable pagination in the table
    page_sizeNumbernullPage size in case pagination is enabled
    can_exportbooleanfalseWhether or not data can be exported to excel
    primary_action_namestring"Edit"Name of button to be set on primary btn. Note: this button still binds to the (edit) function
    secondary_action_namestring"Delete"Name of button to be set on secondary btn. Note: this button still binds to the (delete) function

    Outputs

    AttributeTypeDefaultDescription
    editFunctionnullFunction to be executed on edit click
    deleteFunctionnullA delete function to be executed when user clicks delete
    saveFunctionnullFunction be run on when a user clicks save for inline edit
    cancelFunctionnullFunction be run on when a user clicks cancel for inline edit
    row_clickFunctionnullFunction to handle user row clicks

    An example of inline_edit_group can be seen below:

     inline_edit_groups = [
         {
           binder: 'nums',
           type: 'dropdown',
           options: [1,2,3,4,5]
         },
         {
           binder: 'strs',
           type: 'text'
         }
    ]

Dependencies

This project makes use of the ng2-multiselect library created by preetham1290.

Example code

Example code can be found in the Smarter Table Module

Live Demo

TODO