diff options
Diffstat (limited to 'lib/jquery.jtable.js')
-rw-r--r-- | lib/jquery.jtable.js | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/lib/jquery.jtable.js b/lib/jquery.jtable.js index 0fc911c..273205a 100644 --- a/lib/jquery.jtable.js +++ b/lib/jquery.jtable.js @@ -1,6 +1,6 @@ /* -jTable 2.4.0 +jTable 2.5.0 http://www.jtable.org --------------------------------------------------------------------------- @@ -124,6 +124,8 @@ THE SOFTWARE. _cache: null, //General purpose cache dictionary (object) + _extraFieldTypes:[], + /************************************************************************ * CONSTRUCTOR AND INITIALIZATION METHODS * *************************************************************************/ @@ -167,6 +169,9 @@ THE SOFTWARE. if (props.inputClass == undefined) { props.inputClass = ''; } + if (props.placeholder == undefined) { + props.placeholder = ''; + } //Convert dependsOn to array if it's a comma seperated lists if (props.dependsOn && $.type(props.dependsOn) === 'string') { @@ -186,6 +191,7 @@ THE SOFTWARE. this._columnList = []; this._fieldList = []; this._cache = []; + this._extraFieldTypes = []; }, /* Fills _fieldList, _columnList arrays and sets _keyField variable. @@ -737,7 +743,11 @@ THE SOFTWARE. return field.display({ record: record }); } - if (field.type == 'date') { + var extraFieldType = this._findItemByProperty(this._extraFieldTypes, 'type', field.type); + if(extraFieldType && extraFieldType.creator){ + return extraFieldType.creator(record, field); + } + else if (field.type == 'date') { return this._getDisplayTextForDateRecordField(field, fieldValue); } else if (field.type == 'checkbox') { return this._getCheckBoxTextForFieldByValue(fieldName, fieldValue); @@ -772,13 +782,19 @@ THE SOFTWARE. /* Finds an option object by given value. *************************************************************************/ _findOptionByValue: function (options, value) { - for (var i = 0; i < options.length; i++) { - if (options[i].Value == value) { - return options[i]; + return this._findItemByProperty(options, 'Value', value); + }, + + /* Finds an option object by given value. + *************************************************************************/ + _findItemByProperty: function (items, key, value) { + for (var i = 0; i < items.length; i++) { + if (items[i][key] == value) { + return items[i]; } } - return {}; //no option found + return {}; //no item found }, /* Gets text for a date field. @@ -1608,7 +1624,7 @@ THE SOFTWARE. /* Creates a standart textbox for a field. *************************************************************************/ _createTextInputForField: function (field, fieldName, value) { - var $input = $('<input class="' + field.inputClass + '" id="Edit-' + fieldName + '" type="text" name="' + fieldName + '"></input>'); + var $input = $('<input class="' + field.inputClass + '" placeholder="' + field.placeholder + '" id="Edit-' + fieldName + '" type="text" name="' + fieldName + '"></input>'); if (value != undefined) { $input.val(value); } @@ -1621,7 +1637,7 @@ THE SOFTWARE. /* Creates a password input for a field. *************************************************************************/ _createPasswordInputForField: function (field, fieldName, value) { - var $input = $('<input class="' + field.inputClass + '" id="Edit-' + fieldName + '" type="password" name="' + fieldName + '"></input>'); + var $input = $('<input class="' + field.inputClass + '" placeholder="' + field.placeholder + '" id="Edit-' + fieldName + '" type="password" name="' + fieldName + '"></input>'); if (value != undefined) { $input.val(value); } @@ -2729,7 +2745,7 @@ THE SOFTWARE. var $columns = $tableRow.find('td'); for (var i = 0; i < this._columnList.length; i++) { var displayItem = this._getDisplayTextForRecordField(record, this._columnList[i]); - if ((displayItem != "") && (displayItem == 0)) displayItem = "0"; + if ((displayItem === 0)) displayItem = "0"; $columns.eq(this._firstDataColumnOffset + i).html(displayItem || ''); } @@ -4240,7 +4256,7 @@ THE SOFTWARE. _createHeaderCellForField: function (fieldName, field) { var $headerCell = base._createHeaderCellForField.apply(this, arguments); if (this.options.sorting && field.sorting) { - this._makeColumnSortable($headerCell, fieldName); + this._makeColumnSortable($headerCell, fieldName, field.initialSortingDirection); } return $headerCell; @@ -4287,7 +4303,7 @@ THE SOFTWARE. /* Makes a column sortable. *************************************************************************/ - _makeColumnSortable: function ($columnHeader, fieldName) { + _makeColumnSortable: function ($columnHeader, fieldName, initialSortingDirection) { var self = this; $columnHeader @@ -4302,6 +4318,10 @@ THE SOFTWARE. self._sortTableByColumn($columnHeader); }); + if(initialSortingDirection){ + $columnHeader.addClass('jtable-column-header-sorted-' + initialSortingDirection.toLowerCase()); + } + //Set default sorting $.each(this._lastSorting, function (sortIndex, sortField) { if (sortField.fieldName == fieldName) { |