Skip to content

Repository files navigation

licenseexperiments

AngularJS TableView (example)

A data grid for AngularJS.

Example

Table of contents

  1. Quick Start
  1. Reference API
  1. Complete online usage example

Quick Start

Dependencies

  • No dependencies

Downloading TableView using npm

AngularJS TableView is registered as a package on npm. You can install the latest version of TableView with the command:

npm install angular.tableview

This will install TableView in the node_modules directory. Within node_modules/angular.tableview/dist/ you will find a compressed release files.

Downloading TableView using Bower

AngularJS TableView is also registered as a package with Bower. You can install the latest version of TableView with the command:

bower install angular.tableview

This will install TableView to Bower's install directory, the default being bower_components. Within bower_components/angular.tableview/dist/ you will find a compressed release files.

Make sure to embed it in your HTML document:

<scriptsrc="path/to/angular.min.js"></script><scriptsrc="path/to/dist/angular.tableview.min.js"></script><!-- Required CSS --><linkhref="path/to/dist/angular.tableview.min.css" rel="stylesheet" /><!-- Theme CSS --><linkhref="path/to/dist/angular.tableview.material.min.css" rel="stylesheet" />

Turn on tableview module in the your awesome application:

varapplication=angular.module("app",["tableview"]);

Pass grid configuration via tableview attribute:

<divtableview="configuration"></div>

In the case if you need to completely change default template of tableview directive, you can define path to your template via tableview-template-url attribute:

<divtableview="configuration" tableview-theme="'material'" tableview-template-url="path/to/your/template.html"></div>

Directive attributes:

AttributeTypeDetails
tableviewrequired ObjectTableView instance configuration object
tableview-themeoptional StringThe name of TableView theme to be used here
tableview-template-urloptional StringPath to your custom template of the TableView

All that you needed is to define in your controller configuration and data provider function that receives current request object and callback function as arguments and should provide response object for the current request to the instance of TableView via calling of callback function by passing response object as argument.

Minimal application example:

[index.html]

<htmlng-app="app"><head><scripttype="text/javascript" src="angular.min.js"></script><scripttype="text/javascript" src="angular.tableview.min.js"></script><linkrel="stylesheet" type="text/css" href="angular.tableview.min.css" /><scripttype="text/javascript" src="script.js"></script></head><bodyng-controller="Ctrl"><h1>AngularJS TableView Example</h1><divtableview="configuration"></div></body></html>

[script.js]

angular.module("app",["tableview"]);.controller("Ctrl",function($scope){$scope.configuration={columns: [{field: "id"},{field: "name",title:"Name"},{field: "email",title:"Email"}],provider: provider};functionprovider(request,callback){asyncRequestToServer(request,function(response){callback(response);});}});

Reference API

REQUEST object structure

All properties of the REQUEST object are [optional]

PropertyTypeDetails
limitIntegerHow many entries should to be requested from the server
pageIntegerThe page number, that should to be requested from the server
likeObjectAn object that describes filtering by fields, where name of property is field name and value of property is search string
orderArrayAn array of objects that describes fields with sorting order by which should be sorted result entries
order[x]ObjectAn object that describes sorting order by the field
order[x].fieldStringThe property that defines field name by which should to be sorted result entries
order[x].sortingString `ASCDESC`

Request object example:

varrequest={limit: 10,page: 1,order: [{field:"id",sorting:"ASC"},{field:"name",sorting:"DESC"},{field:"email",sorting:"DESC"},// ...],like: {"name": "John","email": "smith@",// ...}};

RESPONSE object structure

PropertyTypeDetails
limitIntegerLimit that was returned from the server to show results in the TableView. Used for correction of the mapping
pageIntegerThe page number, that was returned from the server. Used for correction of the mapping when it needed (when filters has been applied for example)
amountIntegerSummary amount of the records that available by the sent request. Used for calculation and building of the pager section
rowsArrayAn array of objects (entries) to display considering to request

Response object example:

varresponse={limit: 10,page: 1,amount: 12345,rows: [{"id":123,"name":"John","email":"smith@gmail.com"},// {...}]};

CONFIGURATION object structure

All properties of the CONFIGURATION object except columns and provider are [optional]

PropertyTypeDetails
providerrequired FunctionAccepted arguments: (request, callback). The function that receives current request object and callback function as arguments and should provide response object for the current request to the instance of TableView via calling of callback function by passing response object as argument
columnsrequired ArrayArray of column Objects with definitions of visible columns
column.fieldoptional StringThe name of field in DB that can be used for the sorting and filtering logic. In additional it creates CSS class "column-{{field_name}}" that can be used for UI customisation
column.nameoptional StringAn unique name of the field that can be used for UI customisation from CSS via using of CSS class "column-{{name}}" when field is not defined
column.titleoptional StringThe column title
column.placeholderoptional StringPlaceholder for the filter input. Default: "Search..."
column.sortableoptional BooleanEnables sorting logic for the column. Requires field property. In additional it creates CSS classes "sortable" and "sortable-{{asc
column.filterableoptional BooleanEnables filtering logic for the column. Requires "field" property. In additional it creates CSS class "filterable" that can be used for UI customisation
column.editableoptional Object,BooleanEnables editable logic for the column. Requires "field" property. In additional it creates CSS class "editable" that can be used for UI customisation
column.editable.typeoptional StringAvailable values: text, textarea. Default: text. The type of HTML tag (input or textarea) that will be used in edition mode
column.editable.validateoptional FunctionAccepted arguments: (column, row, field, value). Should return an object: { status: Boolean, message: String }. The function that will be used for validation of the field before changing of the model in edition mode.
column.editable.changeoptional FunctionAccepted arguments: (column, row, field, value). The function that can be used for saving of changed fields on the server.
column.templateoptional ObjectThe list of templates that should to be replaced for the current column cell by using custom templates (see AngularJS ng-template). The name of property is reserved word, that used to define replacement area in TableView template file.
column.template["head.cell"]optional StringAn identifier of template to be used as cell of table header
column.template["body.cell"]optional StringAn identifier of template to be used as cell of table body
column.template["body.cell.edit"]optional StringAn identifier of template to be used as cell of table body in edition (see: editable) mode
column.template["foot.cell"]optional StringAn identifier of template to be used as cell of table footer. Requires of template["foot"] generic template implementation.
templateoptional ObjectThe list of templates that should to be replaced by using custom templates (see AngularJS ng-template). The name of property is reserved word, that used to define replacement area in TableView template file
template["head.cell"]optional StringAn identifier of the generic template to be used as cell of table header
template["head.cell.select"]optional StringAn identifier of the template that contains implementation of toggle selection logic for all rows on the page when selectable logic used
template["body.cell"]optional StringAn identifier of the generic template to be used as cell of table body
template["body.cell.edit"]optional StringAn identifier of the generic template to be used as cell of table body in edition (see: editable) mode
template["body.cell.select"]optional StringAn identifier of the template that contains implementation of toggle selection logic for the current row when selectable logic used
template["foot"]optional StringAn identifier of the generic template to be used as table header. Not implemented by default
template["pager"]optional StringAn identifier of the generic template to be used as pager section of the table
template["pager.limit"]optional StringAn identifier of the generic template to be used as pager limit section of the pager
template["pager.controls"]optional StringAn identifier of the generic template to be used as pager limit controls section of the pager
template["pager.selection"]optional StringAn identifier of the generic template to be used as selection controls section when selectableBy mode enabled
requestoptional ObjectInitial custom request object that can be used to provide stored request from previous user session
multisortingoptional BooleanTurns on multicolumns sorting logic
selectableByoptional StringTurns on rows selection logic by primary key field
scrollableoptional ObjectTurns on scrollable logic for the table area and allows to provide custom styles for scrollable area such as {maxHeight: "400px"}
limitsoptional ArrayDefault: [10, 25, 50, 100]. Custom list of limit numbers
themeoptional StringThe name of the custom TableView theme to be used for the current instance (The material theme as example is available in dist/angular.tableview.material.min.css)

Configuration object example:

$scope.configuration={template: {"head.cell": "your/custom/angular/template.name.html","body.cell": "embed.to.the.view.angular.template.id",},columns: [{field: "field_name",name: "name",title: "Id",placeholder: "Filter placeholder string",sortable:true,filterable:false,editable: {type: "textarea",validate: fieldValidator,change: saveValidChangedField},template: {"head.cell": "your/custom/angular/template.name.html","body.cell": "embed.to.the.view.angular.template.id",},},{field: "simple_editable_field",title: "Title",editable: true}// ...],provider: dataProvider,request: {/* see `REQUEST` structure */},multisorting: false,limits: [10,50,100],scrollable: {maxHeight: "400px"},selectableBy: "id",theme: "material"};functiondataProvider(request,callback){callback(response);}functionfieldValidator(column,row,field,value){varstatus=typeofvalue=="string"&&value.trim().length;return{message: status ? "" : "The field '"+column.title+"' can not be empty",status: status};}functionsaveValidChangedField(column,row,field,value){console.log(arguments.callee.name+"(column, row, field, value) =>",field,"=",value,column,row);}

$tableViewProvider configuration

To define global configuration for your application you can use $tableViewProvider.

For example:

varapp=angular.module("app",["tableview"]);app.config(function($tableViewProvider){$tableViewProvider.theme="material";$tableViewProvider.templateUrl="path/to/your/complete/template.html";$tableViewProvider.template={"head.cell": "your/custom/angular/template.name.html",// ...};});

The list of configuration-dependency CSS classes that provided in the default template

CSS ClassAreaDetails
column-name[tableview]>.holder>table>`theadtbody>tr>th
filterable[tableview]>.holder>table>`theadtbody>tr>th
sortable[tableview]>.holder>table>`theadtbody>tr>th
sortable-`ascdesc`[tableview]>.holder>table>`thead
selectable[tableview]>.holder>table>`theadtbody>tr>th
selected[tableview]>.holder>table>`theadtbody`>tr
scrollable[tableview]To identify that the table is scrollable
editable[tableview]>.holder>table>`theadtbody>tr>th
edition[tableview]>.holder>table>tbody>tr>`thtd`
invalid[tableview]>.holder>table>tbody>tr>`thtd`

About

A data grid for AngularJS

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages