A declarative grid for AngularJS
bower install tc-grid
Basic Usage
angular.module('app', ['tc-grid']);
<link href="bower_components/tc-grid/dest/tc-grid.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="bower_components/tc-grid/dest/tc-grid.js"></script>
<!--
tc-data: Array data source for grid
tc-name: Header name for column
row: single object from array data source
-->
<tc-grid tc-data="dataSource">
<tc-column tc-name="Column Header Name">{{row.dataSourceProperty}}</tc-column>
<tc-column tc-name="Column Header Name">{{row.dataSourceProperty}}</tc-column>
<tc-column tc-name="Column Header Name">{{row.dataSourceProperty}}</tc-column>
<tc-column tc-name="Column Header Name">{{row.dataSourceProperty}}</tc-column>
</tc-grid>
Paging and Sorting
<!--
tc-options: options object to hold paging/sorting info
tc-field: field name to sort on, usually property name
-->
<tc-grid tc-data="dataSource" tc-options="vm.myOptions">
<tc-column tc-name="Column Header Name" tc-field="dataSourceProperty">{{row.dataSourceProperty}}</tc-column>
</tc-grid>
/*
page(int): page to start grid on,
pageSize(int): number of items per page,
sort(array): array with string formatted by "prop dir",
onPageChange(func): called on load and when page is changed,
onSortChange(func): called on load and when sort is changed
*/
angular.module('app').controller('MyController', ['$scope', controller]);
function controller($scope) {
var vm = {
myOptions: {
paging: {
page: 1, //optional
pageSize: 20, //optional
totalItemCount: 200, //optional
onPageChange: function(page, pageSize, sort) {
loadData(page, pageSize, sort);
}
},
sorting: {
sort: ['propName desc'],
onSortChange: function(page, pageSize, sort) {
loadData(page, pageSize, sort);
}
}
}
}
function loadData(page, pageSize, sort) {
//returns data from server
}
}
- tc-grid
- tc-data
- tc-options
- tc-grid-class
- tc-grid-filter
- tc-row-click
- tc-row-class
- row
- tc-column
- tc-name
- tc-field
- tc-col-class
- tc-ignore-click
- tc-visible
Initialize the grid
<tc-grid></tc-grid>
Set the grid's data source
<tc-grid tc-data="dataSource"></tc-grid>
Set the grid's options object
<tc-grid tc-options="gridOptions"></tc-grid>
Set a custom class for the grid
<tc-grid tc-grid-class="gridClass"></tc-grid>
Set a filter function for the grid
<input type="text" ng-model="filterString"/>
<tc-grid tc-grid-filter="myFilter"></tc-grid>
function myFilter(item) {
if(item.Name.indexOf($scope.filterString))
return true;
return false;
}
function called when a row is clicked
<tc-grid tc-row-click="performAction"></tc-grid>
function performAction(row) {
//do something...
}
class to apply to each row
<tc-grid tc-row-class"myClass"></tc-grid>
object available inside tc-column tags giving access to the individual element
individual column element in the grid
supports html markup between the tags
<tc-grid>
<tc-column>{{row.date | date: 'MM/dd/yyyy'}}</tc-column>
</tc-grid>
header name for the column, supports html markup
<tc-grid>
<tc-column tc-name="MyColumn"></tc-column>
</tc-grid>
field to sort on for an individual column
<tc-grid>
<tc-column tc-field="myColumn"></tc-column>
</tc-grid>
class to apply to indiviudal columns
<tc-grid>
<tc-column tc-col-class="myClass"></tc-column>
</tc-grid>
Ignore the row click for the individual column
<tc-grid tc-row-click="performAction">
<!-- calls performAction -->
<tc-column><input type="checkbox"/></tc-column>
<!-- doesn't call performAction -->
<tc-column tc-ignore-click><input type="checkbox"/></tc-column>
</tc-grid>
Toggle column visibility
<input type="checkbox" ng-model="showCol"/>
<tc-grid tc-row-click="performAction">
<tc-column tc-visible="showCol">{{row.name}}</tc-column>
</tc-grid>
- page
- page to start gird on
- pageSize
- items per page
- totalItemCount
- total items
- onPageChange
- called when the page number changes, used to update grid data
- sort
- initial sort to start grid on
['field dir']
- initial sort to start grid on
- onSortChange
- Called when grid is sorted
- columnDisplay
- array of column indexes, names, and/or fields to determine column visibility and order
- reset
- sets paging and sorting to page 1 and no sort
navigate to directory
#install gulp
npm install gulp -g
#install build dependencies
npm install
#run gulp to build less and js
gulp build