1
1
/*
2
2
3
- jTable 2.4 .0
3
+ jTable 2.5 .0
4
4
http://www.jtable.org
5
5
6
6
---------------------------------------------------------------------------
@@ -124,6 +124,8 @@ THE SOFTWARE.
124
124
125
125
_cache : null , //General purpose cache dictionary (object)
126
126
127
+ _extraFieldTypes :[ ] ,
128
+
127
129
/************************************************************************
128
130
* CONSTRUCTOR AND INITIALIZATION METHODS *
129
131
*************************************************************************/
@@ -167,6 +169,9 @@ THE SOFTWARE.
167
169
if ( props . inputClass == undefined ) {
168
170
props . inputClass = '' ;
169
171
}
172
+ if ( props . placeholder == undefined ) {
173
+ props . placeholder = '' ;
174
+ }
170
175
171
176
//Convert dependsOn to array if it's a comma seperated lists
172
177
if ( props . dependsOn && $ . type ( props . dependsOn ) === 'string' ) {
@@ -186,6 +191,7 @@ THE SOFTWARE.
186
191
this . _columnList = [ ] ;
187
192
this . _fieldList = [ ] ;
188
193
this . _cache = [ ] ;
194
+ this . _extraFieldTypes = [ ] ;
189
195
} ,
190
196
191
197
/* Fills _fieldList, _columnList arrays and sets _keyField variable.
@@ -737,7 +743,11 @@ THE SOFTWARE.
737
743
return field . display ( { record : record } ) ;
738
744
}
739
745
740
- if ( field . type == 'date' ) {
746
+ var extraFieldType = this . _findItemByProperty ( this . _extraFieldTypes , 'type' , field . type ) ;
747
+ if ( extraFieldType && extraFieldType . creator ) {
748
+ return extraFieldType . creator ( record , field ) ;
749
+ }
750
+ else if ( field . type == 'date' ) {
741
751
return this . _getDisplayTextForDateRecordField ( field , fieldValue ) ;
742
752
} else if ( field . type == 'checkbox' ) {
743
753
return this . _getCheckBoxTextForFieldByValue ( fieldName , fieldValue ) ;
@@ -772,13 +782,19 @@ THE SOFTWARE.
772
782
/* Finds an option object by given value.
773
783
*************************************************************************/
774
784
_findOptionByValue : function ( options , value ) {
775
- for ( var i = 0 ; i < options . length ; i ++ ) {
776
- if ( options [ i ] . Value == value ) {
777
- return options [ i ] ;
785
+ return this . _findItemByProperty ( options , 'Value' , value ) ;
786
+ } ,
787
+
788
+ /* Finds an option object by given value.
789
+ *************************************************************************/
790
+ _findItemByProperty : function ( items , key , value ) {
791
+ for ( var i = 0 ; i < items . length ; i ++ ) {
792
+ if ( items [ i ] [ key ] == value ) {
793
+ return items [ i ] ;
778
794
}
779
795
}
780
796
781
- return { } ; //no option found
797
+ return { } ; //no item found
782
798
} ,
783
799
784
800
/* Gets text for a date field.
@@ -1608,7 +1624,7 @@ THE SOFTWARE.
1608
1624
/* Creates a standart textbox for a field.
1609
1625
*************************************************************************/
1610
1626
_createTextInputForField : function ( field , fieldName , value ) {
1611
- var $input = $ ( '<input class="' + field . inputClass + '" id="Edit-' + fieldName + '" type="text" name="' + fieldName + '"></input>' ) ;
1627
+ var $input = $ ( '<input class="' + field . inputClass + '" placeholder="' + field . placeholder + '" id="Edit-' + fieldName + '" type="text" name="' + fieldName + '"></input>' ) ;
1612
1628
if ( value != undefined ) {
1613
1629
$input . val ( value ) ;
1614
1630
}
@@ -1621,7 +1637,7 @@ THE SOFTWARE.
1621
1637
/* Creates a password input for a field.
1622
1638
*************************************************************************/
1623
1639
_createPasswordInputForField : function ( field , fieldName , value ) {
1624
- var $input = $ ( '<input class="' + field . inputClass + '" id="Edit-' + fieldName + '" type="password" name="' + fieldName + '"></input>' ) ;
1640
+ var $input = $ ( '<input class="' + field . inputClass + '" placeholder="' + field . placeholder + '" id="Edit-' + fieldName + '" type="password" name="' + fieldName + '"></input>' ) ;
1625
1641
if ( value != undefined ) {
1626
1642
$input . val ( value ) ;
1627
1643
}
@@ -2729,7 +2745,7 @@ THE SOFTWARE.
2729
2745
var $columns = $tableRow . find ( 'td' ) ;
2730
2746
for ( var i = 0 ; i < this . _columnList . length ; i ++ ) {
2731
2747
var displayItem = this . _getDisplayTextForRecordField ( record , this . _columnList [ i ] ) ;
2732
- if ( ( displayItem != "" ) && ( displayItem == 0 ) ) displayItem = "0" ;
2748
+ if ( ( displayItem = == 0 ) ) displayItem = "0" ;
2733
2749
$columns . eq ( this . _firstDataColumnOffset + i ) . html ( displayItem || '' ) ;
2734
2750
}
2735
2751
@@ -4240,7 +4256,7 @@ THE SOFTWARE.
4240
4256
_createHeaderCellForField : function ( fieldName , field ) {
4241
4257
var $headerCell = base . _createHeaderCellForField . apply ( this , arguments ) ;
4242
4258
if ( this . options . sorting && field . sorting ) {
4243
- this . _makeColumnSortable ( $headerCell , fieldName ) ;
4259
+ this . _makeColumnSortable ( $headerCell , fieldName , field . initialSortingDirection ) ;
4244
4260
}
4245
4261
4246
4262
return $headerCell ;
@@ -4287,7 +4303,7 @@ THE SOFTWARE.
4287
4303
4288
4304
/* Makes a column sortable.
4289
4305
*************************************************************************/
4290
- _makeColumnSortable : function ( $columnHeader , fieldName ) {
4306
+ _makeColumnSortable : function ( $columnHeader , fieldName , initialSortingDirection ) {
4291
4307
var self = this ;
4292
4308
4293
4309
$columnHeader
@@ -4302,6 +4318,10 @@ THE SOFTWARE.
4302
4318
self . _sortTableByColumn ( $columnHeader ) ;
4303
4319
} ) ;
4304
4320
4321
+ if ( initialSortingDirection ) {
4322
+ $columnHeader . addClass ( 'jtable-column-header-sorted-' + initialSortingDirection . toLowerCase ( ) ) ;
4323
+ }
4324
+
4305
4325
//Set default sorting
4306
4326
$ . each ( this . _lastSorting , function ( sortIndex , sortField ) {
4307
4327
if ( sortField . fieldName == fieldName ) {
0 commit comments