v1.0.0 - Angular Material Design -- Table Component
Usage
Add module:
angular;
Include file:
;;
Required dependencies
- Angular 1.5.2
- Angular Material 1.0.2
- Angular Translate Support
About Adding your translation
Inside libaray, use {{ value | translate }}
to get the translations.
If you do NOT need translation, you can just pass the string you want to display. If you do need translation, you can pass in the json path as when you use angular translation libaray.
For Example:
<ttmd-table toolbar="{title: 'title.greeting'}"></ttmd-table>
Add missing translations:
In mobile view, there are two buttons needs your provide translations for other languages:
Default value for those are Previous
& Next
Features
Desktop view and mobile view
The default breakpoint is 'xs', able to pass breakpoint
bindings to the component
Force Mobile View
If there is a case you only want to display mobile view, pass in force-mobile
:
Type
To re-render the data efficient, you can have type
:
The type
you pass in , will be the listType
inside js:
thisSomeService
Toolbar
To display the toolbar for the table, passing tooblar
attr. Which is an object contains title
and icon
:
Here icon
is Material font icon: string
Pagination
The desktop and mobile pagination will be handle differently. To enable pagination, need to pass in total-number
to tell how many pages in total. on-page-change
the function need to be called when fetch another page's data.
Sort
Able to sort
data according to the attr, this should be an array, but currently, only work with the first element inside the array.
Exclude
If there is any attr inside the data you don't want to display on the interface, you can use exclude
:
Pipes
You can use Angular built-in filter such as date
& currency
by adding pipies
to format the field:
thispipes = currency: targets: 'amount' 'amountWithOutTax' foramt: '$' // default $, optional date: tragets: 'dueDate' format: 'mm-DD-yyyy'
Highlight Row
You can highlight row by adding highlight-row
to the html:
It takes function:
//Item is sent back with callbackconst someFn = { return ; // parsing some logic}
Change the limits
By default, desktop view show 8 pre-page, mobile view shows 3 pre-page, you can config this for each table:
Action
Besides displaying data, you can pass in action. By default, action will be shown as a button
Text or Button ?
If there is a case you want to display as a button based on prop something
is true, and just display normal text if something
is false.
<!-- Button --> <!-- Text -->
Row Detail
If you want to display more detail information when click the row, you can add <ttmd-detail>
to the code, inside <ttmd-detail>
, passing the directive you want to display. Also add on-row-click
to the
Inside someFn()
function, it will return someData
for your_directive
to display.
{ thissomeData = payload; }
Global Config
It is possible to config for all the tables inside application.
To do that, go to the ngModule.config()
, inject ttmdTableProvider
:
ngModule;
Default Config value
const _defaultConfigs = forceMobile: false breakpoint: 'xs' limits: desktop: 8 mobile: 3
Data Structure
Object
items: Array "serviceCode": "1-260-865-6252 x638" "username": "Milton Mraz" "amount": "8.03" "dueDate": "2016-05-20T05:15:02.719Z" "serviceCode": "1-965-662-5118" "username": "Alessandro Kassulke" "amount": "8.61" "dueDate": "2016-06-25T19:15:02.720Z"
headers: Array (optional)
// Using angular-translate inside the table component, so you need to give the path to find your valuevmheaders = 'some.path.to.value' 'some.path.to.value2'
total-number: number (required if need pagination)
on-page-change: function (required if need pagination)
force-mobile: boolean (optional)
'xs', 'sm', 'md', 'lg'
breakpoint:limits: Object (optional)
vmlimits = desktop: 3 mobile: 3
string
sort: Arraystring
exclude: Arraytoolbar: Object (optional)
vmtoolbar = title: this$translate icon: 'string'
pipes: Object
vmpipes = target: foramt: string
highlight-row: function
type: string (attr on the object) (optional)
show-as: Array[string]
Default: 'button' Available value: 'button', 'text'
if: string: expression
Use the attr on the each object
if= "someAttr > 3"; // if someAttr = 5, then action doesn't show, if someAttr = 2, then action will show