(function(d){function f(a){var b=d.data(a,"propertygrid").options;d(a).datagrid(d.extend({},b,{view:(b.showGroup?e:undefined),onClickRow:function(j,k){if(b.editIndex!=j){var l=d(this).datagrid("getColumnOption","value");l.editor=k.editor;c(b.editIndex);d(this).datagrid("beginEdit",j);d(this).datagrid("getEditors",j)[0].target.focus();b.editIndex=j}b.onClickRow.call(a,j,k)}}));d(a).datagrid("getPanel").panel("panel").addClass("propertygrid");d(a).datagrid("getPanel").find("div.datagrid-body").unbind(".propertygrid").bind("mousedown.propertygrid",function(h){h.stopPropagation()});d(document).unbind(".propertygrid").bind("mousedown.propertygrid",function(){c(b.editIndex);b.editIndex=undefined});function c(j){if(j==undefined){return}var i=d(a);if(i.datagrid("validateRow",j)){i.datagrid("endEdit",j)}else{i.datagrid("cancelEdit",j)}}}d.fn.propertygrid=function(a,b){if(typeof a=="string"){var c=d.fn.propertygrid.methods[a];if(c){return c(this,b)}else{return this.datagrid(a,b)}}a=a||{};return this.each(function(){var h=d.data(this,"propertygrid");if(h){d.extend(h.options,a)}else{d.data(this,"propertygrid",{options:d.extend({},d.fn.propertygrid.defaults,d.fn.propertygrid.parseOptions(this),a)})}f(this)})};d.fn.propertygrid.methods={};d.fn.propertygrid.parseOptions=function(b){var a=d(b);return d.extend({},d.fn.datagrid.parseOptions(b),{showGroup:(a.attr("showGroup")?a.attr("showGroup")=="true":undefined)})};var e=d.extend({},d.fn.datagrid.defaults.view,{render:function(a,D,b){var c=d.data(a,"datagrid").options;var j=d.data(a,"datagrid").data.rows;var w=d(a).datagrid("getColumnFields",b);var x=[];var y=0;var z=this.groups;for(var i=0;i<z.length;i++){var A=z[i];x.push('<div class="datagrid-group" group-index='+i+' style="">');x.push('<table cellspacing="0" cellpadding="0" border="0" style="height:100%"><tbody>');x.push("<tr>");x.push('<td style="border:0;">');if(!b){x.push('<span style="color:#666;font-weight:bold;">');x.push(c.groupFormatter.call(a,A.fvalue,A.rows));x.push("</span>")}x.push("</td>");x.push("</tr>");x.push("</tbody></table>");x.push("</div>");x.push('<table cellspacing="0" cellpadding="0" border="0"><tbody>');for(var u=0;u<A.rows.length;u++){var C=(y%2&&c.striped)?'class="datagrid-row-alt"':"";var B=c.rowStyler?c.rowStyler.call(a,y,A.rows[u]):"";var v=B?'style="'+B+'"':"";x.push('<tr datagrid-row-index="'+y+'" '+C+" "+v+">");x.push(this.renderRow.call(this,a,w,b,y,A.rows[u]));x.push("</tr>");y++}x.push("</tbody></table>")}d(D).html(x.join(""))},onAfterRender:function(a){var b=d.data(a,"datagrid").options;var k=d.data(a,"datagrid").dc;var c=k.view;var l=k.view1;var n=k.view2;d.fn.datagrid.defaults.view.onAfterRender.call(this,a);if(b.rownumbers||b.frozenColumns.length){var m=l.find("div.datagrid-group")}else{var m=n.find("div.datagrid-group")}d('<td style="border:0"><div class="datagrid-row-expander datagrid-row-collapse" style="width:25px;height:16px;cursor:pointer"></div></td>').insertBefore(m.find("td"));c.find("div.datagrid-group").each(function(){var g=d(this).attr("group-index");d(this).find("div.datagrid-row-expander").bind("click",{groupIndex:g},function(h){if(d(this).hasClass("datagrid-row-collapse")){d(a).datagrid("collapseGroup",h.data.groupIndex)}else{d(a).datagrid("expandGroup",h.data.groupIndex)}})})},onBeforeRender:function(r,s){var a=d.data(r,"datagrid").options;var c=[];for(var p=0;p<s.length;p++){var b=s[p];var i=j(b[a.groupField]);if(!i){i={fvalue:b[a.groupField],rows:[b],startRow:p};c.push(i)}else{i.rows.push(b)}}function j(h){for(var k=0;k<c.length;k++){var g=c[k];if(g.fvalue==h){return g}}return null}this.groups=c;var t=[];for(var p=0;p<c.length;p++){var i=c[p];for(var q=0;q<i.rows.length;q++){t.push(i.rows[q])}}d.data(r,"datagrid").data.rows=t}});d.extend(d.fn.datagrid.methods,{expandGroup:function(a,b){return a.each(function(){var c=d.data(this,"datagrid").dc.view;if(b!=undefined){var i=c.find('div.datagrid-group[group-index="'+b+'"]')}else{var i=c.find("div.datagrid-group")}var j=i.find("div.datagrid-row-expander");if(j.hasClass("datagrid-row-expand")){j.removeClass("datagrid-row-expand").addClass("datagrid-row-collapse");i.next("table").show()}d(this).datagrid("fixRowHeight")})},collapseGroup:function(a,b){return a.each(function(){var c=d.data(this,"datagrid").dc.view;if(b!=undefined){var i=c.find('div.datagrid-group[group-index="'+b+'"]')}else{var i=c.find("div.datagrid-group")}var j=i.find("div.datagrid-row-expander");if(j.hasClass("datagrid-row-collapse")){j.removeClass("datagrid-row-collapse").addClass("datagrid-row-expand");i.next("table").hide()}d(this).datagrid("fixRowHeight")})}});d.fn.propertygrid.defaults=d.extend({},d.fn.datagrid.defaults,{singleSelect:true,remoteSort:false,fitColumns:true,loadMsg:"",frozenColumns:[[{field:"f",width:16,resizable:false}]],columns:[[{field:"name",title:"Name",width:100,sortable:true},{field:"value",title:"Value",width:100,resizable:false}]],showGroup:false,groupField:"group",groupFormatter:function(a){return a}})})(jQuery);