Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "jsgrid", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "dist/jsgrid.js", |
{ | ||
"name": "jsgrid", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Lightweight data grid jQuery plugin. It supports basic grid operations like inserting, filtering, editing, deleting, paging and sorting. Although jsGrid is tunable and allows to customize appearance and components.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -175,2 +175,3 @@ # jsGrid Lightweight Grid jQuery Plugin | ||
width: 100, | ||
visible: true, | ||
@@ -209,2 +210,3 @@ css: "", | ||
- **width** is a width of the column. | ||
- **visible** is a boolean specifying whether to show a column or not. (version added: 1.3) | ||
- **css** is a string representing css classes to be attached to the table cell. | ||
@@ -501,8 +503,9 @@ - **headercss** is a string representing css classes to be attached to the table header cell. If not specified, then **css** is attached instead. | ||
{ | ||
align: "center", // center text alignment | ||
autosearch: true, // triggers searching when the user changes the selected item in the filter | ||
items: [], // an array of items for select | ||
valueField: "", // name of property of item to be used as value | ||
textField: "", // name of property of item to be used as displaying value | ||
selectedIndex: -1 // index of selected item by default | ||
align: "center", // center text alignment | ||
autosearch: true, // triggers searching when the user changes the selected item in the filter | ||
items: [], // an array of items for select | ||
valueField: "", // name of property of item to be used as value | ||
textField: "", // name of property of item to be used as displaying value | ||
selectedIndex: -1 // index of selected item by default | ||
valueType: "number|string" // the data type of the value | ||
} | ||
@@ -546,2 +549,5 @@ | ||
`valueType` defines whether the field value should be converted to a number or returned as a string. | ||
The value of the option is determined automatically depending on the data type of `valueField` of the first item, but it can be overridden. | ||
### checkbox | ||
@@ -813,2 +819,25 @@ Checkbox field renders `<input type="checkbox">` in filter, inserting and editing rows. | ||
### fieldOption(fieldName|fieldIndex, optionName, [optionValue]) | ||
> version added: 1.3 | ||
Gets or sets the value of a field option. | ||
**fieldName|fieldIndex** is the name or the index of the field to get/set the option value (if the grid contains more than one field with the same name, the first field will be used). | ||
**optionName** is the name of the field option. | ||
**optionValue** is the new option value to set. | ||
If `optionValue` is not specified, then the value of the field option `optionName` will be returned. | ||
```javascript | ||
// hide the field "ClientName" | ||
$("#grid").jsGrid("fieldOption", "ClientName", "visible", false); | ||
// get width of the 2nd field | ||
var secondFieldOption = $("#grid").jsGrid("fieldOption", 1, "width"); | ||
``` | ||
### insertItem([item]): `Promise` | ||
@@ -861,10 +890,10 @@ Inserts row into the grid based on item. | ||
### option(key, [value]) | ||
### option(optionName, [optionValue]) | ||
Gets or sets the value of an option. | ||
**key** is the name of the option. | ||
**optionName** is the name of the option. | ||
**value** is the new option value to set. | ||
**optionValue** is the new option value to set. | ||
If `value` is not specified, then the value of the option `key` will be returned. | ||
If `optionValue` is not specified, then the value of the option `optionName` will be returned. | ||
@@ -911,2 +940,15 @@ ```javascript | ||
### rowByItem(item): `jQueryElement` | ||
> version added: 1.3 | ||
Gets the row jQuery element corresponding to the item. | ||
**item** is the item corresponding to the row. | ||
```javascript | ||
var $row = $("#grid").jsGrid("rowByItem", item); | ||
``` | ||
### search([filter]): `Promise` | ||
@@ -1008,3 +1050,2 @@ Performs filtering of the grid. | ||
#### jsGrid.setDefaults(config) | ||
Set default options for all grids. | ||
@@ -1022,3 +1063,2 @@ | ||
#### jsGrid.setDefaults(fieldName, config) | ||
Set default options of the particular field. | ||
@@ -1025,0 +1065,0 @@ |
@@ -611,3 +611,3 @@ (function(window, $, undefined) { | ||
var $result; | ||
var fieldValue = item[field.name]; | ||
var fieldValue = this._getItemFieldValue(item, field); | ||
@@ -628,2 +628,34 @@ if($.isFunction(field.cellRenderer)) { | ||
_getItemFieldValue: function(item, field) { | ||
var props = field.name.split('.'); | ||
var result = item[props.shift()]; | ||
while(result && props.length) { | ||
result = result[props.shift()]; | ||
} | ||
return result; | ||
}, | ||
_setItemFieldValue: function(item, field, value) { | ||
var props = field.name.split('.'); | ||
var current = item; | ||
var prop = props[0]; | ||
while(current && props.length > 1) { | ||
item = current; | ||
prop = props.shift(); | ||
current = item[prop]; | ||
} | ||
if(!current) { | ||
while(props.length) { | ||
item = item[prop] = {}; | ||
prop = props.shift(); | ||
} | ||
} | ||
item[prop] = value; | ||
}, | ||
sort: function(field, order) { | ||
@@ -996,3 +1028,3 @@ if($.isPlainObject(field)) { | ||
if(field.filtering) { | ||
result[field.name] = field.filterValue(); | ||
this._setItemFieldValue(result, field, field.filterValue()); | ||
} | ||
@@ -1049,3 +1081,3 @@ }); | ||
if(field.inserting) { | ||
result[field.name] = field.insertValue(); | ||
this._setItemFieldValue(result, field, field.insertValue()); | ||
} | ||
@@ -1104,5 +1136,7 @@ }); | ||
this._eachField(function(field) { | ||
var fieldValue = this._getItemFieldValue(item, field); | ||
$("<td>").addClass(field.editcss || field.css) | ||
.appendTo($result) | ||
.append(field.editTemplate ? field.editTemplate(item[field.name], item) : "") | ||
.append(field.editTemplate ? field.editTemplate(fieldValue, item) : "") | ||
.width(field.width || "auto"); | ||
@@ -1128,5 +1162,5 @@ }); | ||
updatingItemIndex = this._itemIndex(updatingItem), | ||
previousItem = $.extend({}, updatingItem); | ||
previousItem = $.extend(true, {}, updatingItem); | ||
$.extend(updatingItem, editedItem); | ||
$.extend(true, updatingItem, editedItem); | ||
@@ -1170,3 +1204,3 @@ var args = this._callEventHandler(this.onItemUpdating, { | ||
if(field.editing) { | ||
result[field.name] = field.editValue(); | ||
this._setItemFieldValue(result, field, field.editValue()); | ||
} | ||
@@ -1173,0 +1207,0 @@ }); |
@@ -10,3 +10,3 @@ (function(jsGrid, $, undefined) { | ||
name: "", | ||
title: "", | ||
title: null, | ||
css: "", | ||
@@ -24,3 +24,3 @@ align: "", | ||
headerTemplate: function() { | ||
return this.title || this.name; | ||
return (this.title === undefined || this.title === null) ? this.name : this.title; | ||
}, | ||
@@ -27,0 +27,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
810103
17260
1792
50