Populate database lists in a datatable with pagination,search, buttons, data exports and more in just 1 minute
Felix Kakra Acheampong from (Orcons Systems
) Ghana
-[X] Database items display view
-[X] Select input pagination
-[X] Next and previous pagination with tooltip
-[X] Database search input bar and button
-[X] Add button if hasAddButton
is set to true
-[X] Buttons in each item row if hasActionButtons
is set to true
. Note that the maximum number of buttons in each row is 3. Exceeding the number will not have an event attached to it.
V 1.0.6
Angular 6.
You can install flx-ui-datatable using npm
npm install flx-ui-datatable
To enable document print work. Add the two links to your angular.json, or your index.html
<script type="text/javascript" src="https://printjs-4de6.kxcdn.com/print.min.js"></script>
<link rel="stylesheet" type="text/css" src="https://printjs-4de6.kxcdn.com/print.min.css">
<flx-ui-datatable
[headers]="['Fullname','Email','Phone Number','Address']"
[dataKeys]="['FULLNAME','MOBILENUMBER','GENDER','DESCRIPTION']"
[dataUrl]="'http://domain/?something=something'"
[dataSrcKey]="'data'"
[actionButtons]="[{text:'Edit',icon:'fa fa-edit',class:'btn btn-danger'}]"
[limit]="10"
[hasAddButton]="true"
[searchPlaceholder]="'Enter description to search'"
(firstActionButtonClicked)="fButtonClicked($event)">
</flx-ui-datatable>
If data from api is Array<Object>
([{},{}]
), Then do not specify [dataSrcKey]
,
If data from api is JSON Object
{'status':200,'data':[{},{}]}
with data
key holding
your database records, then set [dataSrcKey]
to data
;
headers
(Array<string>
) - Array of strings containing table headers. Headers for the table;dataKeys
(Array<string>
) - Array of strings containing keys from API to display;dataSrcKey
(string
) - Data items to read from response payload if data is aJSON OBJECT
;hasActionButtons
(boolean
) - Boolean to specify if datatable has action buttons in each row. Default isfalse
;enableDataExports
(boolean
) Enable table data exportdataExportsConfig
({}
) configure which type of document to show export. ({exportsTo:[],title:'',dataColumns:[]}}
).exportsTo
(Array<string>
) (print|word|pdf|excel
). You can enable more than two or all of them.title
(string
) Title to show on the export popup menu.dataColumns
(Array<string>
) Data keys to include in the export. If not specified, this will export document usingdataKeys
(Input
) by default.hideNumbers
(boolean
) - Determine if datatable should be numbered. Default istrue
;enableMultipleSelection
(boolean
) - Set to true to enable multiple deletion on the datatable. Also setmultipleSelectKey
to push all the seleted items in an array. Default isfalse
;hasAddButton
(boolean
) Show add button. Default is false. Default isfalse
;dataUrl
(string
) Api url to load data from. This is aGET
http request;searchPlaceholder
(string
) Change placeholder of the search input;actionButtons
(Array<Object>
). Action buttons to display in each datatable row.spinnerSrc
(string
) spinner image/gif to show when loading data from API.showBottomInfo
(boolean
) Show table bottom info. This include (Total items
,Total pagination in the table
,Number of items per pagination
){text:'View'}
This will display a button in each datatable row with a text lableView
Advance{text:'View',background:'',textColor:'',icon:'',iconPosition:''
}text
Text to display in the button.background
Change background-color of the buttontextColor
Change textcolor of the buttonicon
Add icon to the button. icon can be from fontawsome or bootstrap glyphicons. example icon:'fa fa-user'iconPosition
Icon position. Default isleft
multipleSelectButton
({text:'',icon:''}
)
dataSrcKey
Example. If data response is{status:200,data:[...]}
, then setdataSrcKey
todata
Else if response is[...]
, then leavedataSrcKey
empty or do not set it.limit
(string
) Number of items per pagination.paginationButtons
({}
) pagination buttons style{background:'',textColor:''}
Change background-color and text-color of the pagination buttons;tableHeader
({}
) Change table header background-color and text-color{background:'',textColor:''}
;searchButton
({}
) Change background and text color of the search button Example{background:'#cccccc',textColor:'#335599'}
;addButton
({}
) Change background and text color of add button Example{background:'#335599',textColor:'#ffffff'}
;searchBar
({}
) Change search input bar style Example{borderSize:'1px',borderColor:'#ccc',background:'#ffffff',textColor:'#000000'}
tableType
(string
) Default is table-striped. Change it to any table type class ;actionHeader
(string
) Table button header text. Default isActions
classes
({}
): {paginationselect
: Pagination select class;addButton
: Add button class;exportButton
: Export button right class;tableType
: Table class. Exampletable-striped|table-hover
;tableHeader
: Table header class;tableData
: Table td class;SearchBar
: Search bar class;reloadbutton
: Reload button class } ;
By default this library search through all DataKeys
and if match is found result output to the table.
This can be controlled by specifying which DataKeys
to search. Example [DataKeys]="['FULLNAME']
.
This will only search through FULLNAME column datakey rather than searching multiple of datakey columns.
firstActionButtonClicked()
({index:number,data:Object})
First button in a row click.index
= The position of the clicked itemdata
= All data in the item position;secondActionButtonClicked()
Second button in a row click.index
= The position of the clicked itemdata
= All data in the item position;thirdActionButtonClicked()
Third button in a row click.index
= The position of the clicked itemdata
= All data in the item position;mutipleSelectionClicked()
(Array<any>
) Multiple item deletion click. Returns an array of data giving inmultipleDeleteKey
variable. You can send this data to using your own DELETE request to perform deletion from your Database.addButtonClicked
Handle add button.
import { FlxUiDatatableModule,FlxUiDataTable } from 'flx-ui-datatable' ;
//In your app @ngModuel imports
imports:[FlxUiDatatableModule],
providers:[FlxUiDataTable]
//In your page.ts file
import { FlxUiDataTable } from 'flx-ui-datatable' ;
constructor(public dataService:FlxUiDataTable){}
//To reload data from your API
this.dataService.flxReloadData() ;
//To cancel http request to your API
this.dataService.abortRequest() ;
//To get all the data
this.dataService.flxDatatableData.subscribe((data) => {
// data is
data ;
}) ;
In this sample, FULLNAME
will be read from API response payload for Fullname table header column
Contributions are welcome. You can start by checking and bug or the way this can be improved by emailing to [email protected]