@@ -19,6 +19,9 @@ describe('ng-table', () => {
19
19
20
20
interface ICustomizedScope extends IScope {
21
21
$$childHead : INgTableChildScope ;
22
+ model : {
23
+ exportedCols ?: IColumnDef [ ] ;
24
+ } ;
22
25
ageFilter : IFilterTemplateDefMap ;
23
26
ageExpandedFilter : { [ name : string ] : IFilterTemplateDef } ;
24
27
ageTitle : string | { ( ) : string } ;
@@ -66,6 +69,7 @@ describe('ng-table', () => {
66
69
beforeEach ( inject ( ( $rootScope : IScope , _$compile_ : ICompileService ) => {
67
70
scope = $rootScope . $new ( true ) as ICustomizedScope ;
68
71
$compile = _$compile_ ;
72
+ scope . model = { } ;
69
73
} ) ) ;
70
74
71
75
function createNgTableParams < T > ( initialParams ?: IParamValues < T > , settings ?: ISettings < T > ) : NgTableParams < T > ;
@@ -399,7 +403,7 @@ describe('ng-table', () => {
399
403
// given
400
404
const { params, tableElm } = createTable ( tableWithSortableAgeColumnTpl ) ;
401
405
( params . settings ( ) . getData as jasmine . Spy ) . calls . reset ( ) ;
402
- const columnHeader =
406
+ const columnHeader =
403
407
tableElm [ 0 ] . querySelector ( '.ng-table-sort-header > th' ) as HTMLTableHeaderCellElement ;
404
408
405
409
// when
@@ -809,10 +813,10 @@ describe('ng-table', () => {
809
813
810
814
describe ( '$columns' , ( ) => {
811
815
let tableElm : IAugmentedJQuery ,
812
- tp : NgTableParams < IPerson > ;
816
+ params : NgTableParams < IPerson > ;
813
817
beforeEach ( ( ) => {
814
818
const html = `<div>
815
- <table ng-table="tableParams">
819
+ <table ng-table="tableParams" ng-table-columns-binding="model.exportedCols" >
816
820
<tr ng-repeat="user in $data">
817
821
<td title="ageTitle" ng-if="isAgeVisible" filter="ageFilter">{{user.age}}</td>
818
822
<td title="'Name'" groupable="'name'" sortable="'name'">{{user.name}}</td>
@@ -824,12 +828,12 @@ describe('ng-table', () => {
824
828
} ;
825
829
scope . isAgeVisible = true ;
826
830
scope . ageTitle = 'Age' ;
827
- ( { params : tp , tableElm } = createTable ( html ) ) ;
831
+ ( { params, tableElm } = createTable ( html ) ) ;
828
832
} ) ;
829
833
830
834
it ( 'should make $columns available on the scope created for ng-table' , ( ) => {
831
835
// check that the scope is indeed the one created for out NgTableParams
832
- expect ( scope . $$childHead . params ) . toBe ( tp ) ;
836
+ expect ( scope . $$childHead . params ) . toBe ( params ) ;
833
837
834
838
expect ( scope . $$childHead . $columns ) . toBeDefined ( ) ;
835
839
} ) ;
@@ -838,12 +842,16 @@ describe('ng-table', () => {
838
842
expect ( scope [ '$columns' ] ) . toBeUndefined ( ) ;
839
843
} ) ;
840
844
845
+ it ( 'ng-table-columns-binding should make $columns externally available' , ( ) => {
846
+ expect ( scope . model . exportedCols ) . toBeDefined ( ) ;
847
+ } ) ;
848
+
841
849
it ( '$scolumns should contain a column definition for each `td` element' , ( ) => {
842
- expect ( scope . $$childHead . $columns . length ) . toBe ( 2 ) ;
850
+ expect ( scope . model . exportedCols . length ) . toBe ( 2 ) ;
843
851
} ) ;
844
852
845
853
it ( 'each column definition should have getters for each column attribute' , ( ) => {
846
- const ageCol = scope . $$childHead . $columns [ 0 ] ;
854
+ const ageCol = scope . model . exportedCols [ 0 ] ;
847
855
expect ( ageCol . title ( ) ) . toBe ( 'Age' ) ;
848
856
expect ( ageCol . show ( ) ) . toBe ( true ) ;
849
857
expect ( ageCol . filter ( ) ) . toBe ( scope . ageFilter ) ;
@@ -855,7 +863,7 @@ describe('ng-table', () => {
855
863
expect ( ageCol . sortable ( ) ) . toBe ( false ) ;
856
864
expect ( ageCol . titleAlt ( ) ) . toBe ( '' ) ;
857
865
858
- const nameCol = scope . $$childHead . $columns [ 1 ] ;
866
+ const nameCol = scope . model . exportedCols [ 1 ] ;
859
867
expect ( nameCol . title ( ) ) . toBe ( 'Name' ) ;
860
868
expect ( nameCol . show ( ) ) . toBe ( true ) ;
861
869
expect ( nameCol . filter ( ) ) . toBe ( false ) ;
@@ -869,7 +877,7 @@ describe('ng-table', () => {
869
877
} ) ;
870
878
871
879
it ( 'each column attribute should be assignable' , ( ) => {
872
- const ageCol = scope . $$childHead . $columns [ 0 ] ;
880
+ const ageCol = scope . model . exportedCols [ 0 ] ;
873
881
874
882
ageCol . title . assign ( scope . $$childHead , 'Age of person' ) ;
875
883
expect ( ageCol . title ( ) ) . toBe ( 'Age of person' ) ;
@@ -903,14 +911,58 @@ describe('ng-table', () => {
903
911
expect ( ageCol . titleAlt ( ) ) . toBe ( 'really' ) ;
904
912
905
913
906
- const nameCol = scope . $$childHead . $columns [ 1 ] ;
914
+ const nameCol = scope . model . exportedCols [ 1 ] ;
907
915
908
916
nameCol . groupable . assign ( scope . $$childHead , false ) ;
909
917
expect ( nameCol . groupable ( ) ) . toBe ( false ) ;
910
918
911
919
nameCol . sortable . assign ( scope . $$childHead , false ) ;
912
920
expect ( nameCol . sortable ( ) ) . toBe ( false ) ;
913
921
} ) ;
922
+
923
+ it ( 'each column attribute should be settable' , ( ) => {
924
+ const ageCol = scope . model . exportedCols [ 0 ] ;
925
+
926
+ ageCol . title ( 'Age of person' ) ;
927
+ expect ( ageCol . title ( ) ) . toBe ( 'Age of person' ) ;
928
+ expect ( scope . ageTitle ) . toBe ( 'Age of person' ) ;
929
+
930
+ ageCol . show ( false ) ;
931
+ expect ( ageCol . show ( ) ) . toBe ( false ) ;
932
+ expect ( scope . isAgeVisible ) . toBe ( false ) ;
933
+
934
+ const newFilter : IFilterTemplateDefMap = { age : 'select' } ;
935
+ ageCol . filter ( newFilter ) ;
936
+ expect ( ageCol . filter ( ) ) . toBe ( newFilter ) ;
937
+ expect ( scope . ageFilter ) . toBe ( newFilter ) ;
938
+
939
+ ageCol . class ( 'amazing' ) ;
940
+ expect ( ageCol . class ( ) ) . toBe ( 'amazing' ) ;
941
+
942
+ ageCol . groupable ( 'age' ) ;
943
+ expect ( ageCol . groupable ( ) ) . toBe ( 'age' ) ;
944
+
945
+ ageCol . headerTemplateURL ( 'some.html' ) ;
946
+ expect ( ageCol . headerTemplateURL ( ) ) . toBe ( 'some.html' ) ;
947
+
948
+ ageCol . headerTitle ( 'wow' ) ;
949
+ expect ( ageCol . headerTitle ( ) ) . toBe ( 'wow' ) ;
950
+
951
+ ageCol . sortable ( 'incredible' ) ;
952
+ expect ( ageCol . sortable ( ) ) . toBe ( 'incredible' ) ;
953
+
954
+ ageCol . titleAlt ( 'really' ) ;
955
+ expect ( ageCol . titleAlt ( ) ) . toBe ( 'really' ) ;
956
+
957
+
958
+ const nameCol = scope . model . exportedCols [ 1 ] ;
959
+
960
+ nameCol . groupable ( false ) ;
961
+ expect ( nameCol . groupable ( ) ) . toBe ( false ) ;
962
+
963
+ nameCol . sortable ( false ) ;
964
+ expect ( nameCol . sortable ( ) ) . toBe ( false ) ;
965
+ } ) ;
914
966
} ) ;
915
967
916
968
0 commit comments