diff --git a/bower.json b/bower.json index d4efdf22..8d37ebf0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jsgrid", - "version": "1.3.0", + "version": "1.3.1", "main": [ "dist/jsgrid.js", "dist/jsgrid.css", diff --git a/dist/jsgrid-theme.css b/dist/jsgrid-theme.css index 33fec514..58334744 100644 --- a/dist/jsgrid-theme.css +++ b/dist/jsgrid-theme.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.3.0 (http://js-grid.com) + * jsGrid v1.3.1 (http://js-grid.com) * (c) 2015 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid-theme.min.css b/dist/jsgrid-theme.min.css index c101464f..08a37080 100644 --- a/dist/jsgrid-theme.min.css +++ b/dist/jsgrid-theme.min.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.3.0 (http://js-grid.com) + * jsGrid v1.3.1 (http://js-grid.com) * (c) 2015 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid.css b/dist/jsgrid.css index e668621a..95b51df3 100644 --- a/dist/jsgrid.css +++ b/dist/jsgrid.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.3.0 (http://js-grid.com) + * jsGrid v1.3.1 (http://js-grid.com) * (c) 2015 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid.js b/dist/jsgrid.js index 0760e18b..18b39935 100644 --- a/dist/jsgrid.js +++ b/dist/jsgrid.js @@ -1,5 +1,5 @@ /* - * jsGrid v1.3.0 (http://js-grid.com) + * jsGrid v1.3.1 (http://js-grid.com) * (c) 2015 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ @@ -614,7 +614,7 @@ _createCell: function(item, field) { var $result; - var fieldValue = item[field.name]; + var fieldValue = this._getItemFieldValue(item, field); if($.isFunction(field.cellRenderer)) { $result = $(field.cellRenderer(fieldValue, item)); @@ -630,6 +630,38 @@ return $result; }, + _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) { if($.isPlainObject(field)) { order = field.order; @@ -997,7 +1029,7 @@ var result = {}; this._eachField(function(field) { if(field.filtering) { - result[field.name] = field.filterValue(); + this._setItemFieldValue(result, field, field.filterValue()); } }); return result; @@ -1049,7 +1081,7 @@ var result = {}; this._eachField(function(field) { if(field.inserting) { - result[field.name] = field.insertValue(); + this._setItemFieldValue(result, field, field.insertValue()); } }); return result; @@ -1103,9 +1135,11 @@ var $result = $("").addClass(this.editRowClass); this._eachField(function(field) { + var fieldValue = this._getItemFieldValue(item, field); + $("").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"); }); @@ -1126,9 +1160,9 @@ _updateRow: function($updatingRow, editedItem) { var updatingItem = $updatingRow.data(JSGRID_ROW_DATA_KEY), updatingItemIndex = this._itemIndex(updatingItem), - previousItem = $.extend({}, updatingItem); + previousItem = $.extend(true, {}, updatingItem); - $.extend(updatingItem, editedItem); + $.extend(true, updatingItem, editedItem); var args = this._callEventHandler(this.onItemUpdating, { row: $updatingRow, @@ -1167,7 +1201,7 @@ var result = {}; this._eachField(function(field) { if(field.editing) { - result[field.name] = field.editValue(); + this._setItemFieldValue(result, field, field.editValue()); } }); return result; @@ -1515,7 +1549,7 @@ Field.prototype = { name: "", - title: "", + title: null, css: "", align: "", width: 100, @@ -1528,7 +1562,7 @@ sorter: "string", // name of SortStrategy or function to compare elements headerTemplate: function() { - return this.title || this.name; + return (this.title === undefined || this.title === null) ? this.name : this.title; }, itemTemplate: function(value, item) { diff --git a/dist/jsgrid.min.css b/dist/jsgrid.min.css index 508b67b2..a3173a0c 100644 --- a/dist/jsgrid.min.css +++ b/dist/jsgrid.min.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.3.0 (http://js-grid.com) + * jsGrid v1.3.1 (http://js-grid.com) * (c) 2015 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid.min.js b/dist/jsgrid.min.js index 4ba4d34f..95b59ad3 100644 --- a/dist/jsgrid.min.js +++ b/dist/jsgrid.min.js @@ -1,7 +1,7 @@ /* - * jsGrid v1.3.0 (http://js-grid.com) + * jsGrid v1.3.1 (http://js-grid.com) * (c) 2015 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ -!function(a,b,c){function d(a,c){var d=b(a);d.data(f,this),this._container=d,this.data=[],this.fields=[],this._editingRow=null,this._sortField=null,this._sortOrder=i,this._firstDisplayingPage=1,this._init(c),this.render()}var e="JSGrid",f=e,g="JSGridItem",h="JSGridEditRow",i="asc",j="desc",k="{first}",l="{pages}",m="{prev}",n="{next}",o="{last}",p="{pageIndex}",q="{pageCount}",r="{itemCount}",s="javascript:void(0);",t=function(a,c){return b.isFunction(a)?a.apply(c,b.makeArray(arguments).slice(2)):a},u={loadData:b.noop,insertItem:b.noop,updateItem:b.noop,deleteItem:b.noop};d.prototype={width:"auto",height:"auto",updateOnResize:!0,rowClass:b.noop,rowRenderer:null,rowClick:function(a){this.editing&&this.editItem(b(a.event.target).closest("tr"))},rowDoubleClick:b.noop,noDataContent:"Not found",noDataRowClass:"jsgrid-nodata-row",heading:!0,headerRowRenderer:null,headerRowClass:"jsgrid-header-row",filtering:!1,filterRowRenderer:null,filterRowClass:"jsgrid-filter-row",inserting:!1,insertRowRenderer:null,insertRowClass:"jsgrid-insert-row",editing:!1,editRowRenderer:null,editRowClass:"jsgrid-edit-row",confirmDeleting:!0,deleteConfirm:"Are you sure?",selecting:!0,selectedRowClass:"jsgrid-selected-row",oddRowClass:"jsgrid-row",evenRowClass:"jsgrid-alt-row",sorting:!1,sortableClass:"jsgrid-header-sortable",sortAscClass:"jsgrid-header-sort jsgrid-header-sort-asc",sortDescClass:"jsgrid-header-sort jsgrid-header-sort-desc",paging:!1,pagerContainer:null,pageIndex:1,pageSize:20,pageButtonCount:15,pagerFormat:"Pages: {first} {prev} {pages} {next} {last}    {pageIndex} of {pageCount}",pagePrevText:"Prev",pageNextText:"Next",pageFirstText:"First",pageLastText:"Last",pageNavigatorNextText:"...",pageNavigatorPrevText:"...",pagerContainerClass:"jsgrid-pager-container",pagerClass:"jsgrid-pager",pagerNavButtonClass:"jsgrid-pager-nav-button",pagerNavButtonInactiveClass:"jsgrid-pager-nav-inactive-button",pageClass:"jsgrid-pager-page",currentPageClass:"jsgrid-pager-current-page",customLoading:!1,pageLoading:!1,autoload:!1,controller:u,loadIndication:!0,loadIndicationDelay:500,loadMessage:"Please, wait...",loadShading:!0,onRefreshing:b.noop,onRefreshed:b.noop,onItemDeleting:b.noop,onItemDeleted:b.noop,onItemInserting:b.noop,onItemInserted:b.noop,onItemUpdating:b.noop,onItemUpdated:b.noop,onDataLoading:b.noop,onDataLoaded:b.noop,onOptionChanging:b.noop,onOptionChanged:b.noop,onError:b.noop,containerClass:"jsgrid",tableClass:"jsgrid-table",gridHeaderClass:"jsgrid-grid-header",gridBodyClass:"jsgrid-grid-body",_init:function(a){b.extend(this,a),this._initLoadStrategy(),this._initController(),this._initFields(),this._attachWindowLoadResize(),this._attachWindowResizeCallback()},loadStrategy:function(){return this.pageLoading?new jsGrid.loadStrategies.PageLoadingStrategy(this):new jsGrid.loadStrategies.DirectLoadingStrategy(this)},_initLoadStrategy:function(){this._loadStrategy=t(this.loadStrategy,this)},_initController:function(){this._controller=b.extend({},u,t(this.controller,this))},loadIndicator:function(a){return new jsGrid.LoadIndicator(a)},_initFields:function(){var a=this;a.fields=b.map(a.fields,function(c){if(b.isPlainObject(c)){var d=c.type&&jsGrid.fields[c.type]||jsGrid.Field;c=new d(c)}return c._grid=a,c})},_attachWindowLoadResize:function(){b(a).on("load",b.proxy(this._refreshSize,this))},_attachWindowResizeCallback:function(){this.updateOnResize&&b(a).on("resize",b.proxy(this._refreshSize,this))},_detachWindowResizeCallback:function(){b(a).off("resize",this._refreshSize)},option:function(a,b){var c,d;return 1===arguments.length?this[a]:(c={option:a,oldValue:this[a],newValue:b},this._callEventHandler(this.onOptionChanging,c),this._handleOptionChange(c.option,c.newValue),d={option:c.option,value:c.newValue},void this._callEventHandler(this.onOptionChanged,d))},fieldOption:function(a,b,c){return a=this._normalizeField(a),2===arguments.length?a[b]:(a[b]=c,void this._renderGrid())},_handleOptionChange:function(a,b){switch(this[a]=b,a){case"width":case"height":this._refreshSize();break;case"rowClass":case"rowRenderer":case"rowClick":case"rowDoubleClick":case"noDataText":case"noDataRowClass":case"noDataContent":case"selecting":case"selectedRowClass":case"oddRowClass":case"evenRowClass":this._refreshContent();break;case"pageButtonCount":case"pagerFormat":case"pagePrevText":case"pageNextText":case"pageFirstText":case"pageLastText":case"pageNavigatorNextText":case"pageNavigatorPrevText":case"pagerClass":case"pagerNavButtonClass":case"pageClass":case"currentPageClass":case"pagerRenderer":this._refreshPager();break;case"fields":this._initFields(),this.render();break;case"data":case"editing":case"heading":case"filtering":case"inserting":case"paging":this.refresh();break;case"loadStrategy":case"pageLoading":this._initLoadStrategy(),this.search();break;case"pageIndex":this.openPage(b);break;case"pageSize":this.refresh(),this.search();break;case"editRowRenderer":case"editRowClass":this.cancelEdit();break;case"updateOnResize":this._detachWindowResizeCallback(),this._attachWindowResizeCallback();break;default:this.render()}},destroy:function(){this._detachWindowResizeCallback(),this._clear(),this._container.removeData(f)},render:function(){return this._renderGrid(),this.autoload?this.loadData():b.Deferred().resolve().promise()},_renderGrid:function(){this._clear(),this._container.addClass(this.containerClass).css("position","relative").append(this._createHeader()).append(this._createBody()),this._pagerContainer=this._createPagerContainer(),this._loadIndicator=this._createLoadIndicator(),this.refresh()},_createLoadIndicator:function(){return t(this.loadIndicator,this,{message:this.loadMessage,shading:this.loadShading,container:this._container})},_clear:function(){this.cancelEdit(),clearTimeout(this._loadingTimer),this._pagerContainer&&this._pagerContainer.empty(),this._container.empty().css({position:"",width:"",height:""})},_createHeader:function(){var a=this._headerRow=this._createHeaderRow(),c=this._filterRow=this._createFilterRow(),d=this._insertRow=this._createInsertRow(),e=this._headerGrid=b("").addClass(this.tableClass).append(a).append(c).append(d),f=this._header=b("
").addClass(this.gridHeaderClass).addClass(this._scrollBarWidth()?"jsgrid-header-scrollbar":"").append(e);return f},_createBody:function(){var a=this._content=b("
"),c=this._bodyGrid=b("
").addClass(this.tableClass).append(a),d=this._body=b("
").addClass(this.gridBodyClass).append(c).on("scroll",b.proxy(function(a){this._header.scrollLeft(a.target.scrollLeft)},this));return d},_createPagerContainer:function(){var a=this.pagerContainer||b("
").appendTo(this._container);return b(a).addClass(this.pagerContainerClass)},_eachField:function(a){var c=this;b.each(this.fields,function(b,d){d.visible&&a.call(c,d,b)})},_createHeaderRow:function(){if(b.isFunction(this.headerRowRenderer))return b(this.headerRowRenderer());var a=b("
").addClass(this.headerRowClass);return this._eachField(function(c,d){var e=b("").addClass(this.filterRowClass);return this._eachField(function(c){b("").addClass(this.insertRowClass);return this._eachField(function(c){b("").addClass(this.noDataRowClass).append(b(""),this._renderCells(d,a)),d.addClass(this._getRowClasses(a,c)).data(g,a).on("click",b.proxy(function(b){this.rowClick({item:a,itemIndex:c,event:b})},this)).on("dblclick",b.proxy(function(b){this.rowDoubleClick({item:a,itemIndex:c,event:b})},this)),this.selecting&&this._attachRowHover(d),d},_getRowClasses:function(a,b){var c=[];return c.push((b+1)%2?this.oddRowClass:this.evenRowClass),c.push(t(this.rowClass,this,a,b)),c.join(" ")},_attachRowHover:function(a){var c=this.selectedRowClass;a.hover(function(){b(this).addClass(c)},function(){b(this).removeClass(c)})},_renderCells:function(a,b){return this._eachField(function(c){a.append(this._createCell(b,c))}),this},_createCell:function(a,c){var d,e=a[c.name];return d=b.isFunction(c.cellRenderer)?b(c.cellRenderer(e,a)):b("").addClass(this.editRowClass);return this._eachField(function(d){b("
").addClass(c.headercss||c.css).appendTo(a).append(c.headerTemplate?c.headerTemplate():"").css("width",c.width);this.sorting&&c.sorting&&e.addClass(this.sortableClass).on("click",b.proxy(function(){this.sort(d)},this))}),a},_createFilterRow:function(){if(b.isFunction(this.filterRowRenderer))return b(this.filterRowRenderer());var a=b("
").addClass(c.filtercss||c.css).appendTo(a).append(c.filterTemplate?c.filterTemplate():"").width(c.width)}),a},_createInsertRow:function(){if(b.isFunction(this.insertRowRenderer))return b(this.insertRowRenderer());var a=b("
").addClass(c.insertcss||c.css).appendTo(a).append(c.insertTemplate?c.insertTemplate():"").width(c.width)}),a},_callEventHandler:function(a,c){return a.call(this,b.extend(c,{grid:this})),c},reset:function(){this._resetSorting(),this._resetPager(),this.refresh()},_resetPager:function(){this._firstDisplayingPage=1,this._setPage(1)},_resetSorting:function(){this._sortField=null,this._sortOrder=i,this._clearSortingCss()},refresh:function(){this._callEventHandler(this.onRefreshing),this.cancelEdit(),this._refreshHeading(),this._refreshFiltering(),this._refreshInserting(),this._refreshContent(),this._refreshPager(),this._refreshSize(),this._callEventHandler(this.onRefreshed)},_refreshHeading:function(){this._headerRow.toggle(this.heading)},_refreshFiltering:function(){this._filterRow.toggle(this.filtering)},_refreshInserting:function(){this._insertRow.toggle(this.inserting)},_refreshContent:function(){var a=this._content;if(a.empty(),!this.data.length)return a.append(this._createNoDataRow()),this;for(var b=this._loadStrategy.firstDisplayIndex(),c=this._loadStrategy.lastDisplayIndex(),d=b;c>d;d++){var e=this.data[d];a.append(this._createRow(e,d))}},_createNoDataRow:function(){var a=t(this.noDataContent,this),c=0;return this._eachField(function(){c++}),b("
").attr("colspan",c).append(a))},_createNoDataContent:function(){return b.isFunction(this.noDataRenderer)?this.noDataRenderer():this.noDataText},_createRow:function(a,c){var d;return b.isFunction(this.rowRenderer)?d=b(this.rowRenderer(a,c)):(d=b("
").append(c.itemTemplate?c.itemTemplate(e,a):e),d.addClass(c.css).width(c.width),c.align&&d.addClass("jsgrid-align-"+c.align),d},sort:function(a,c){return b.isPlainObject(a)&&(c=a.order,a=a.field),this._clearSortingCss(),this._setSortingParams(a,c),this._setSortingCss(),this._loadStrategy.sort()},_clearSortingCss:function(){this._headerRow.find("th").removeClass(this.sortAscClass).removeClass(this.sortDescClass)},_setSortingParams:function(a,b){a=this._normalizeField(a),b=b||(this._sortField===a?this._reversedSortOrder(this._sortOrder):i),this._sortField=a,this._sortOrder=b},_normalizeField:function(a){return b.isNumeric(a)?this.fields[a]:"string"==typeof a?b.grep(this.fields,function(b){return b.name===a})[0]:a},_reversedSortOrder:function(a){return a===i?j:i},_setSortingCss:function(){var a=b.inArray(this._sortField,this.fields);this._headerRow.find("th").eq(a).addClass(this._sortOrder===i?this.sortAscClass:this.sortDescClass)},_sortData:function(){var a=this._sortFactor(),b=this._sortField;b&&this.data.sort(function(c,d){return a*b.sortingFunc(c[b.name],d[b.name])})},_sortFactor:function(){return this._sortOrder===i?1:-1},_itemsCount:function(){return this._loadStrategy.itemsCount()},_pagesCount:function(){var a=this._itemsCount(),b=this.pageSize;return Math.floor(a/b)+(a%b?1:0)},_refreshPager:function(){var a=this._pagerContainer;a.empty(),this.paging&&a.append(this._createPager());var b=this.paging&&this._pagesCount()>1;a.toggle(b)},_createPager:function(){var a;return a=b.isFunction(this.pagerRenderer)?b(this.pagerRenderer({pageIndex:this.pageIndex,pageCount:this._pagesCount()})):b("
").append(this._createPagerByFormat()),a.addClass(this.pagerClass),a},_createPagerByFormat:function(){var a=this.pageIndex,c=this._pagesCount(),d=this._itemsCount(),e=this.pagerFormat.split(" ");return b.map(e,b.proxy(function(e){var f=e;return e===l?f=this._createPages():e===k?f=this._createPagerNavButton(this.pageFirstText,1,a>1):e===m?f=this._createPagerNavButton(this.pagePrevText,a-1,a>1):e===n?f=this._createPagerNavButton(this.pageNextText,a+1,c>a):e===o?f=this._createPagerNavButton(this.pageLastText,c,c>a):e===p?f=a:e===q?f=c:e===r&&(f=d),b.isArray(f)?f.concat([" "]):[f," "]},this))},_createPages:function(){var a,b=this._pagesCount(),c=this.pageButtonCount,d=this._firstDisplayingPage,e=[];d>1&&e.push(this._createPagerPageNavButton(this.pageNavigatorPrevText,this.showPrevPages));for(var f=0,a=d;c>f&&b>=a;f++,a++)e.push(a===this.pageIndex?this._createPagerCurrentPage():this._createPagerPage(a));return b>d+c-1&&e.push(this._createPagerPageNavButton(this.pageNavigatorNextText,this.showNextPages)),e},_createPagerNavButton:function(a,c,d){return this._createPagerButton(a,this.pagerNavButtonClass+(d?"":" "+this.pagerNavButtonInactiveClass),d?function(){this.openPage(c)}:b.noop)},_createPagerPageNavButton:function(a,b){return this._createPagerButton(a,this.pagerNavButtonClass,b)},_createPagerPage:function(a){return this._createPagerButton(a,this.pageClass,function(){this.openPage(a)})},_createPagerButton:function(a,c,d){var e=b("").attr("href",s).html(a).on("click",b.proxy(d,this));return b("").addClass(c).append(e)},_createPagerCurrentPage:function(){return b("").addClass(this.pageClass).addClass(this.currentPageClass).text(this.pageIndex)},_refreshSize:function(){this._refreshHeight(),this._refreshWidth()},_refreshWidth:function(){var a=this._headerGrid,b=this._bodyGrid,c=this.width;"auto"===c&&(a.width("auto"),c=a.outerWidth()),a.width(""),b.width(""),this._container.width(c),c=a.outerWidth(),b.width(c)},_scrollBarWidth:function(){var a;return function(){if(a===c){var d=b("
"),e=b("
");d.append(e).appendTo("body");var f=e.innerWidth();d.css("overflow-y","auto");var g=e.innerWidth();d.remove(),a=f-g}return a}}(),_refreshHeight:function(){var a,b=this._container,c=this._pagerContainer,d=this.height;b.height(d),"auto"!==d&&(d=b.height(),a=this._header.outerHeight(!0),c.parents(b).length&&(a+=c.outerHeight(!0)),this._body.outerHeight(d-a))},showPrevPages:function(){var a=this._firstDisplayingPage,b=this.pageButtonCount;this._firstDisplayingPage=a>b?a-b:1,this._refreshPager()},showNextPages:function(){var a=this._firstDisplayingPage,b=this.pageButtonCount,c=this._pagesCount();this._firstDisplayingPage=a+2*b>c?c-b+1:a+b,this._refreshPager()},openPage:function(a){1>a||a>this._pagesCount()||(this._setPage(a),this._loadStrategy.openPage(a))},_setPage:function(a){var b=this._firstDisplayingPage,c=this.pageButtonCount;this.pageIndex=a,b>a&&(this._firstDisplayingPage=a),a>b+c-1&&(this._firstDisplayingPage=a-c+1)},_controllerCall:function(a,c,d,e){if(d)return b.Deferred().reject().promise();this._showLoading();var f=this._controller;if(!f||!f[a])throw new Error("controller has no method '"+a+"'");return b.when(f[a](c)).done(b.proxy(e,this)).fail(b.proxy(this._errorHandler,this)).always(b.proxy(this._hideLoading,this))},_errorHandler:function(){this._callEventHandler(this.onError,{args:b.makeArray(arguments)})},_showLoading:function(){this.loadIndication&&(clearTimeout(this._loadingTimer),this._loadingTimer=setTimeout(b.proxy(function(){this._loadIndicator.show()},this),this.loadIndicationDelay))},_hideLoading:function(){this.loadIndication&&(clearTimeout(this._loadingTimer),this._loadIndicator.hide())},search:function(a){return this._resetSorting(),this._resetPager(),this.loadData(a)},loadData:function(a){a=a||(this.filtering?this.getFilter():{}),b.extend(a,this._loadStrategy.loadParams(),this._sortingParams());var c=this._callEventHandler(this.onDataLoading,{filter:a});return this._controllerCall("loadData",a,c.cancel,function(a){a&&(this._loadStrategy.finishLoad(a),this._callEventHandler(this.onDataLoaded,{data:a}))})},getFilter:function(){var a={};return this._eachField(function(b){b.filtering&&(a[b.name]=b.filterValue())}),a},_sortingParams:function(){return this.sorting&&this._sortField?{sortField:this._sortField.name,sortOrder:this._sortOrder}:{}},getSorting:function(){var a=this._sortingParams();return{field:a.sortField,order:a.sortOrder}},clearFilter:function(){var a=this._createFilterRow();return this._filterRow.replaceWith(a),this._filterRow=a,this.search()},insertItem:function(a){var b=a||this._getInsertItem(),c=this._callEventHandler(this.onItemInserting,{item:b});return this._controllerCall("insertItem",b,c.cancel,function(a){a=a||b,this._loadStrategy.finishInsert(a),this._callEventHandler(this.onItemInserted,{item:a})})},_getInsertItem:function(){var a={};return this._eachField(function(b){b.inserting&&(a[b.name]=b.insertValue())}),a},clearInsert:function(){var a=this._createInsertRow();this._insertRow.replaceWith(a),this._insertRow=a,this.refresh()},editItem:function(a){var b=this.rowByItem(a);b.length&&this._editRow(b)},rowByItem:function(a){return a.jquery||a.nodeType?b(a):this._content.find("tr").filter(function(){return b.data(this,g)===a})},_editRow:function(a){if(this.editing){this._editingRow&&this.cancelEdit();var b=a.data(g),c=this._createEditRow(b);this._editingRow=a,a.hide(),c.insertAfter(a),a.data(h,c)}},_createEditRow:function(a){if(b.isFunction(this.editRowRenderer))return b(this.editRowRenderer(a,this._itemIndex(a)));var c=b("
").addClass(d.editcss||d.css).appendTo(c).append(d.editTemplate?d.editTemplate(a[d.name],a):"").width(d.width||"auto")}),c},updateItem:function(a,b){1===arguments.length&&(b=a);var c=a?this.rowByItem(a):this._editingRow;return b=b||this._getEditedItem(),this._updateRow(c,b)},_updateRow:function(a,c){var d=a.data(g),e=this._itemIndex(d),f=b.extend({},d);b.extend(d,c);var h=this._callEventHandler(this.onItemUpdating,{row:a,item:d,itemIndex:e,previousItem:f});return this._controllerCall("updateItem",d,h.cancel,function(b){b=b||d;var c=this._finishUpdate(a,b,e);this._callEventHandler(this.onItemUpdated,{row:c,item:b,itemIndex:e,previousItem:f})})},_itemIndex:function(a){return b.inArray(a,this.data)},_finishUpdate:function(a,b,c){this.cancelEdit(),this.data[c]=b;var d=this._createRow(b,c);return a.replaceWith(d),d},_getEditedItem:function(){var a={};return this._eachField(function(b){b.editing&&(a[b.name]=b.editValue())}),a},cancelEdit:function(){if(this._editingRow){var a=this._editingRow,b=a.data(h);b.remove(),a.show(),this._editingRow=null}},deleteItem:function(b){var c=this.rowByItem(b);if(c.length&&(!this.confirmDeleting||a.confirm(t(this.deleteConfirm,this,c.data(g)))))return this._deleteRow(c)},_deleteRow:function(a){var b=a.data(g),c=this._itemIndex(b),d=this._callEventHandler(this.onItemDeleting,{row:a,item:b,itemIndex:c});return this._controllerCall("deleteItem",b,d.cancel,function(){this._loadStrategy.finishDelete(b,c),this._callEventHandler(this.onItemDeleted,{row:a,item:b,itemIndex:c})})}},b.fn.jsGrid=function(a){var e=b.makeArray(arguments),g=e.slice(1),h=this;return this.each(function(){var e,i=b(this),j=i.data(f);if(j)if("string"==typeof a){if(e=j[a].apply(j,g),e!==c&&e!==j)return h=e,!1}else j._detachWindowResizeCallback(),j._init(a),j.render();else new d(i,a)}),h};var v={},w=function(a){var c;b.isPlainObject(a)?c=d.prototype:(c=v[a].prototype,a=arguments[1]||{}),b.extend(c,a)};a.jsGrid={Grid:d,fields:v,setDefaults:w}}(window,jQuery),function(a,b){function c(a){this._init(a)}c.prototype={container:"body",message:"Loading...",shading:!0,zIndex:1e3,shaderClass:"jsgrid-load-shader",loadPanelClass:"jsgrid-load-panel",_init:function(a){b.extend(!0,this,a),this._initContainer(),this._initShader(),this._initLoadPanel()},_initContainer:function(){this._container=b(this.container)},_initShader:function(){this.shading&&(this._shader=b("
").addClass(this.shaderClass).hide().css({position:"absolute",top:0,right:0,bottom:0,left:0,zIndex:this.zIndex}).appendTo(this._container))},_initLoadPanel:function(){this._loadPanel=b("
").addClass(this.loadPanelClass).text(this.message).hide().css({position:"absolute",top:"50%",left:"50%",zIndex:this.zIndex}).appendTo(this._container)},show:function(){var a=this._loadPanel.show(),b=a.outerWidth(),c=a.outerHeight();a.css({marginTop:-c/2,marginLeft:-b/2}),this._shader.show()},hide:function(){this._loadPanel.hide(),this._shader.hide()}},a.LoadIndicator=c}(jsGrid,jQuery),function(a,b){function c(a){this._grid=a}function d(a){this._grid=a,this._itemsCount=0}c.prototype={firstDisplayIndex:function(){var a=this._grid;return a.option("paging")?(a.option("pageIndex")-1)*a.option("pageSize"):0},lastDisplayIndex:function(){var a=this._grid,b=a.option("data").length;return a.option("paging")?Math.min(a.option("pageIndex")*a.option("pageSize"),b):b},itemsCount:function(){return this._grid.option("data").length},openPage:function(){this._grid.refresh()},loadParams:function(){return{}},sort:function(){return this._grid._sortData(),this._grid.refresh(),b.Deferred().resolve().promise()},finishLoad:function(a){this._grid.option("data",a)},finishInsert:function(a){var b=this._grid;b.option("data").push(a),b.refresh()},finishDelete:function(a,b){var c=this._grid;c.option("data").splice(b,1),c.reset()}},d.prototype={firstDisplayIndex:function(){return 0},lastDisplayIndex:function(){return this._grid.option("data").length},itemsCount:function(){return this._itemsCount},openPage:function(){this._grid.loadData()},loadParams:function(){var a=this._grid;return{pageIndex:a.option("pageIndex"),pageSize:a.option("pageSize")}},sort:function(){return this._grid.loadData()},finishLoad:function(a){this._itemsCount=a.itemsCount,this._grid.option("data",a.data)},finishInsert:function(){this._grid.search()},finishDelete:function(){this._grid.search()}},a.loadStrategies={DirectLoadingStrategy:c,PageLoadingStrategy:d}}(jsGrid,jQuery),function(a){var b=function(a){return"undefined"!=typeof a&&null!==a},c={string:function(a,c){return b(a)||b(c)?b(a)?b(c)?(""+a).localeCompare(""+c):1:-1:0},number:function(a,b){return a-b},date:function(a,b){return a-b},numberAsString:function(a,b){return parseFloat(a)-parseFloat(b)}};a.sortStrategies=c}(jsGrid,jQuery),function(a,b){function c(a){b.extend(!0,this,a),this.sortingFunc=this._getSortingFunc()}c.prototype={name:"",title:"",css:"",align:"",width:100,visible:!0,filtering:!0,inserting:!0,editing:!0,sorting:!0,sorter:"string",headerTemplate:function(){return this.title||this.name},itemTemplate:function(a){return a},filterTemplate:function(){return""},insertTemplate:function(){return""},editTemplate:function(a,b){return this._value=a,this.itemTemplate(a,b)},filterValue:function(){return""},insertValue:function(){return""},editValue:function(){return this._value},_getSortingFunc:function(){var c=this.sorter;if(b.isFunction(c))return c;if("string"==typeof c)return a.sortStrategies[c];throw Error('Wrong sorter for the field "'+this.name+'"!')}},a.Field=c}(jsGrid,jQuery),function(a,b){function c(a){d.call(this,a)}var d=a.Field;c.prototype=new d({autosearch:!0,filterTemplate:function(){if(!this.filtering)return"";var a=this._grid,b=this.filterControl=this._createTextBox();return this.autosearch&&b.on("keypress",function(b){13===b.which&&(a.search(),b.preventDefault())}),b},insertTemplate:function(){if(!this.inserting)return"";var a=this.insertControl=this._createTextBox();return a},editTemplate:function(a){if(!this.editing)return this.itemTemplate(a);var b=this.editControl=this._createTextBox();return b.val(a),b},filterValue:function(){return this.filterControl.val()},insertValue:function(){return this.insertControl.val()},editValue:function(){return this.editControl.val()},_createTextBox:function(){return b("").attr("type","text")}}),a.fields.text=a.TextField=c}(jsGrid,jQuery),function(a,b){function c(a){d.call(this,a)}var d=a.TextField;c.prototype=new d({sorter:"number",align:"right",filterValue:function(){return parseInt(this.filterControl.val()||0,10)},insertValue:function(){return parseInt(this.insertControl.val()||0,10)},editValue:function(){return parseInt(this.editControl.val()||0,10)},_createTextBox:function(){return b("").attr("type","number")}}),a.fields.number=a.NumberField=c}(jsGrid,jQuery),function(a,b){function c(a){d.call(this,a)}var d=a.TextField;c.prototype=new d({insertTemplate:function(){if(!this.inserting)return"";var a=this.insertControl=this._createTextArea();return a},editTemplate:function(a){if(!this.editing)return this.itemTemplate(a);var b=this.editControl=this._createTextArea();return b.val(a),b},_createTextArea:function(){return b("