开源软件名称(OpenSource Name):iamisti/mdDataTable开源软件地址(OpenSource Url):https://github.com/iamisti/mdDataTable开源编程语言(OpenSource Language):JavaScript 83.1%开源软件介绍(OpenSource Introduction):
Angular material table. Complete implementation of google material design based on angular material components. This component is optimized for speed, and it's faster then other similar implementations, since it generates a native html table, and browsers are optimized for tables.
Usage statisticsInstall
Load it from CDN (with example of version 1.8.0)https://cdnjs.cloudflare.com/ajax/libs/md-data-table/1.8.0/md-data-table-templates.min.js https://cdnjs.cloudflare.com/ajax/libs/md-data-table/1.8.0/md-data-table.min.js https://cdnjs.cloudflare.com/ajax/libs/md-data-table/1.8.0/md-data-table-style.css UI&UX driven by google data tablehttp://www.google.com/design/spec/components/data-tables.html Table of contents
Column attributes (
Custom cell content (
Overview
Table attributes
Example usage for |
Available | Params | Type | Details |
---|---|---|---|
mdt-row-paginator | Function | optional, makes possible to provide a callback function which returns a promise, providing the data for the table. Has two parameters: page and pageSize (an optional parameter is options as a third parameter, which can have columnFilter property when column-filter is used or columnSort when you turn on column sorting feature |
|
mdt-row-paginator-error-message | String | optional, overrides default error mesasge when promise gets rejected by the paginator function. | |
mdt-row-paginator-no-results-message | String | optional, overrides default 'no results' message when there are no results in the table. | |
mdt-trigger-request | function(loadPageCallback) | optional, if mdt-row-paginator set, provides a callback function for manually triggering an ajax request. Can be useful when you want to populate the results in the table manually. (e.g.: having a search field in your page which then can trigger a new request in the table to show the results based on that filter. |
mdt-row-paginator
attribute:<mdt-table
paginated-rows="{isEnabled: true, rowsPerPageValues: [5,10,20,100]}"
mdt-row-paginator="paginatorCallback(page, pageSize, options)"
mdt-row-paginator-error-message="Error happened during loading nutritions."
mdt-row="{
'table-row-id-key': 'fields.item_id',
'column-keys': [
'fields.item_name',
'fields.nf_calories',
'fields.nf_total_fat',
'fields.nf_total_carbohydrate',
'fields.nf_protein',
'fields.nf_sodium',
'fields.nf_calcium_dv',
'fields.nf_iron_dv'
],
}">
<mdt-header-row>
<mdt-column align-rule="left">Dessert (100g serving)</mdt-column>
<mdt-column align-rule="right">Calories</mdt-column>
<mdt-column align-rule="right">Fat (g)</mdt-column>
<mdt-column align-rule="right">Carbs (g)</mdt-column>
<mdt-column align-rule="right">Protein (g)</mdt-column>
<mdt-column align-rule="right">Sodium (mg)</mdt-column>
<mdt-column align-rule="right">Calcium (%)</mdt-column>
<mdt-column align-rule="right">Iron (%)</mdt-column>
</mdt-header-row>
</mdt-table>
mdt-column
attributes
Available | Params | ChildPArams | Type | Details |
---|---|---|---|---|
align-rule | String | if provided, align the text to the needed direction for the entire column (note, that it aligns the data that belongs to the column) | ||
(default) left | left-align content | |||
right | right-align content |
Available | Params | ChildPArams | Type | Details |
---|---|---|---|---|
sortable-rows-default | - | When column-sort is applied to the table, it marks the column as the default sorting column | ||
column-sort | Boolean | Object | ||
column-sort | true | false | ||
column-sort | comparator | in case of object, specifying a 'comparator' property which is a function for sorting the column data's. As every compare function, it gets two parameters and return with the compared result (-1,1,0) |
Available | Params | ChildPArams | Type | Details |
---|---|---|---|---|
column-filter | Object | if provided, user can activate column filter feature on the selected column. | ||
valuesProviderCallback | Function | required, function which provides the values into the column filter. It must return with a promise which resolves an array of strings/objects. | ||
valuesTransformerCallback | Function | optional, function which transforms the provided objects into strings to be able to show it visually in the column filter. | ||
placeholderText | Text | optional, placeholder which will show up as a default text (available only for chips and dropdown filter types |
||
filterType | Text | optional, defines the type of the filter you want to use. Available options are: chips , checkbox , dropdown . If you don't specify it, the default will be chips |
||
exclude-from-column-selector | Boolean | optional, excludes the column from the column selection feature | ||
hide-column-by-default | Boolean | optional, make column unselected by default in the column selection panel |
When filters are applied to the columns, a third parameter will be applied to the
mdt-row-paginator
callback function.
mdt-row
attributes
Available | Params | Type | Details |
---|---|---|---|
table-row-id | String | Integer |
mdt-custom-cell
attributes
If you are using mdt-row
attribute to load your data (which is only way of you are dealing with ajax contents), you can now have custom content for each cells you defined.
Important information:
You can still access your scope variables/functions with accessing
clientScope
within themdt-custom-cell
directive. The value of the cell can be accessed by accessingvalue
inside the directive. AccessingrowId
also possible if you specified it withtable-row-id-key
.
Available | Params | ChildParams | Type | Details |
---|---|---|---|---|
column-key | String | required, specifies the column in the rows. | ||
There is only one scope variable that you can use in your template, and it's called value . Check the example. |
mdt-custom-cell
:<mdt-table>
<mdt-table mdt-row="{'data': filteredItems,
'table-row-id-key': 'id',
'column-keys': ['name', 'calories', 'fat', 'carbs', 'protein', 'sodium', 'calcium', 'iron']}">
<mdt-header-row>
<mdt-column align-rule="left">Dessert (100g serving)</mdt-column>
<mdt-column align-rule="right">Calories</mdt-column>
<mdt-column align-rule="right">Fat (g)</mdt-column>
<mdt-column align-rule="right">Carbs (g)</mdt-column>
<mdt-column align-rule="right">Protein (g)</mdt-column>
<mdt-column align-rule="right">Sodium (mg)</mdt-column>
<mdt-column align-rule="right">Calcium (%)</mdt-column>
<mdt-column align-rule="right">Iron (%)</mdt-column>
</mdt-header-row>
<!-- here you have your own, customised cell for every 'protein' column -->
<mdt-custom-cell column-key="protein">
<span ng-class="{'red': value > 5, 'green': value <= 5}">{{value}}</span>
<span ng-click="clientScope.myMethodToExecute()">click here</span>
<span>This is the row id for this column: {{rowId}}</span>
</mdt-custom-cell>
</mdt-table>
</mdt-table>
mdt-cell
attributes
请发表评论