@@ -438,13 +438,13 @@ var ngTableController = ['$scope', 'ngTableParams', '$q', function($scope, ngTab
438
438
} , true ) ;
439
439
440
440
$scope . sortBy = function ( column ) {
441
- var sorting , sortingParams ;
442
- if ( ! column . sortable ) {
441
+ var parsedSortable = $scope . parse ( column . sortable ) ;
442
+ if ( ! parsedSortable ) {
443
443
return ;
444
444
}
445
- sorting = $scope . params . sorting ( ) && $scope . params . sorting ( ) [ column . sortable ] && ( $scope . params . sorting ( ) [ column . sortable ] === "desc" ) ;
446
- sortingParams = { } ;
447
- sortingParams [ column . sortable ] = ( sorting ? 'asc' : 'desc' ) ;
445
+ var sorting = $scope . params . sorting ( ) && $scope . params . sorting ( ) [ parsedSortable ] && ( $scope . params . sorting ( ) [ parsedSortable ] === "desc" ) ;
446
+ var sortingParams = { } ;
447
+ sortingParams [ parsedSortable ] = ( sorting ? 'asc' : 'desc' ) ;
448
448
$scope . params . parameters ( {
449
449
sorting : sortingParams
450
450
} ) ;
@@ -496,27 +496,30 @@ app.directive('ngTable', ['$compile', '$q', '$parse',
496
496
if ( el . attr ( 'ignore-cell' ) && 'true' === el . attr ( 'ignore-cell' ) ) {
497
497
return ;
498
498
}
499
- var parsedTitle = function ( scope ) {
500
- return $parse ( el . attr ( 'x-data-title' ) || el . attr ( 'data-title' ) || el . attr ( 'title' ) ) ( scope , {
501
- $columns : columns
502
- } ) || ' ' ;
503
- } ;
504
- el . attr ( 'data-title-text' , parsedTitle ( ) ) ;
505
- var headerTemplateURL = function ( scope ) {
506
- return $parse ( el . attr ( "x-data-header" ) || el . attr ( "data-header" ) || el . attr ( "header" ) ) ( scope , {
507
- $columns : columns
508
- } ) || false ;
499
+ var parsedAttribute = function ( attr , defaultValue ) {
500
+ return function ( scope ) {
501
+ return $parse ( el . attr ( 'x-data-' + attr ) || el . attr ( 'data-' + attr ) || el . attr ( attr ) ) ( scope , {
502
+ $columns : columns
503
+ } ) || defaultValue ;
504
+ } ;
509
505
} ;
510
- var filter = el . attr ( "filter" ) ? $parse ( el . attr ( "filter" ) ) ( ) : false ;
511
- var filterTemplateURL = false ;
506
+
507
+ var parsedTitle = parsedAttribute ( 'title' , ' ' ) ,
508
+ headerTemplateURL = parsedAttribute ( 'header' , false ) ( ) ,
509
+ filter = parsedAttribute ( 'filter' , false ) ( ) ,
510
+ filterTemplateURL = false ;
511
+
512
512
if ( filter && filter . templateURL ) {
513
513
filterTemplateURL = filter . templateURL ;
514
514
delete filter . templateURL ;
515
515
}
516
+
517
+ // this used in responsive table
518
+ el . attr ( 'data-title-text' , parsedTitle ( ) ) ;
516
519
columns . push ( {
517
520
id : i ++ ,
518
521
title : parsedTitle ,
519
- sortable : ( el . attr ( " sortable" ) ? el . attr ( "sortable" ) : false ) ,
522
+ sortable : parsedAttribute ( ' sortable' , false ) ,
520
523
filter : filter ,
521
524
filterTemplateURL : filterTemplateURL ,
522
525
headerTemplateURL : headerTemplateURL ,
@@ -594,7 +597,7 @@ app.directive('ngTable', ['$compile', '$q', '$parse',
594
597
angular . module ( 'ngTable' ) . run ( [ '$templateCache' , function ( $templateCache ) {
595
598
$templateCache . put ( 'ng-table/filters/select.html' , '<select ng-options="data.id as data.title for data in column.data" ng-model="params.filter()[name]" ng-show="filter==\'select\'" class="filter filter-select form-control"> </select>' ) ;
596
599
$templateCache . put ( 'ng-table/filters/text.html' , '<input type="text" ng-model="params.filter()[name]" ng-if="filter==\'text\'" class="input-filter form-control"/>' ) ;
597
- $templateCache . put ( 'ng-table/header.html' , '<tr> <th ng-repeat="column in $columns" ng-class="{ \'sortable\': column.sortable, \'sort-asc\': params.sorting()[column.sortable]==\'asc\', \'sort-desc\': params.sorting()[column.sortable]==\'desc\', column.class: true }" ng-click="sortBy(column)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header"> <div ng-if="!template" ng-bind="parse(column.title)"></div> <div ng-if="template"><div ng-include="template"></div></div> </th> </tr> <tr ng-show="show_filter" class="ng-table-filters"> <th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter"> <div ng-repeat="(name, filter) in column.filter"> <div ng-if="column.filterTemplateURL"> <div ng-include="column.filterTemplateURL"></div> </div> <div ng-if="!column.filterTemplateURL"> <div ng-include="\'ng-table/filters/\' + filter + \'.html\'"></div> </div> </div> </th> </tr>' ) ;
600
+ $templateCache . put ( 'ng-table/header.html' , '<tr> <th ng-repeat="column in $columns" ng-class="{ \'sortable\': parse( column.sortable) , \'sort-asc\': params.sorting()[parse( column.sortable) ]==\'asc\', \'sort-desc\': params.sorting()[parse( column.sortable) ]==\'desc\', column.class: true }" ng-click="sortBy(column)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header"> <div ng-if="!template" ng-bind="parse(column.title)"></div> <div ng-if="template"><div ng-include="template"></div></div> </th> </tr> <tr ng-show="show_filter" class="ng-table-filters"> <th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter"> <div ng-repeat="(name, filter) in column.filter"> <div ng-if="column.filterTemplateURL"> <div ng-include="column.filterTemplateURL"></div> </div> <div ng-if="!column.filterTemplateURL"> <div ng-include="\'ng-table/filters/\' + filter + \'.html\'"></div> </div> </div> </th> </tr>' ) ;
598
601
$templateCache . put ( 'ng-table/pager.html' , '<div class="ng-cloak"> <div ng-if="params.settings().counts.length" class="btn-group pull-right"> <button ng-repeat="count in params.settings().counts" type="button" ng-class="{\'active\':params.count()==count}" ng-click="params.count(count)" class="btn btn-default btn-xs"> <span ng-bind="count"></span> </button> </div> <ul class="pagination"> <li ng-class="{\'disabled\': !page.active}" ng-repeat="page in pages" ng-switch="page.type"> <a ng-switch-when="prev" ng-click="params.page(page.number)" href="">«</a> <a ng-switch-when="first" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="page" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="more" ng-click="params.page(page.number)" href="">…</a> <a ng-switch-when="last" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="next" ng-click="params.page(page.number)" href="">»</a> </li> </ul> </div>' ) ;
599
602
} ] ) ;
600
603
return app ;
0 commit comments