jQWidgets Forums
jQuery UI Widgets › Forums › Grid › aggregates in dynamic columns
This topic contains 11 replies, has 2 voices, and was last updated by Peter Stoev 11 years, 5 months ago.
-
Author
-
Hi,
I am creating my grid dynamically (Columns created) from server.
How can I apply aggregates rendering on specific columns.Hi Sethu,
It is possible to customize the aggregates by using that approach: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/aggregatesrenderer.htm?arctic
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Peter,
Thank you for your response. But by columns are being created dynamically and I creating it using the approach you specified in this blog. http://www.jqwidgets.com/community/reply/reply-to-dynamic-columns-in-grid-8/.
Because my columns have aggregates renderer Javascript jqxGrid is throwing error.Thank you.
Hi Sethu,
If you would like, you can send us a full sample with your scenario so we would be able to test it locally.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Peter,
Sure. Below is the code:
var columnsSource = {
datatype: ‘json’,
datafields: ”,
type: ‘GET’,
url: ‘Service.asmx/GetColumns’,
async: false
};var gridColumns = “”;
var columnsDataAdapter = new $.jqx.dataAdapter(columnsSource, {
contentType: ‘application/json; charset=utf-8’,
loadError: function (xhr, status, error) {
alert(error);
},
downloadComplete: function (data) {
var returnData = {};
var obj = data.d;returnData.records = “[{ text: ‘ID’, dataField: ‘ID’, width: 250 }]”;
gridColumns = data.d;
// return returnData;
}
});
columnsDataAdapter.dataBind();
$(“#jqxgrid”).jqxGrid({
width: ‘100%’,
height: ‘100%’,
theme: theme,
source: dataAdapter,
altrows: true,
editable: true,
columnsresize: true,
columnsreorder: true,
showstatusbar: true,
showaggregates: true,
showtoolbar: true,
autoheight: false,
columns: [
{ text: ‘ID’, dataField: ‘ID’, width: 250 }
],});
$(“#jqxgrid”).jqxGrid({ columns: gridColumns });
The code from ASP.NET Service is below:
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public object GetColumns()
{
var data = @”[
{ text: ‘ID’, dataField: ‘ID’, width: 250 },
{ text: ‘MATCH STATUS’, dataField: ‘MATCH_STATUS’, editable:false, width: 150, aggregates: [‘count’] },
{ text: ‘EXCEPTION DATE’, dataField: ‘EXCEPTION_DATE’, editable:false, width: 180, columntype: ‘datetime’, format: ‘MM/dd/yyyy’ },
{ text: ‘KEY ID’, dataField: ‘KEY_ID’, width: 180,editable:false, cellsalign: ‘right’, cellsformat: ‘c2’, aggregates: [‘sum’],
aggregatesrenderer: “”function (aggregates) {
return aggregates[sum];
}””
},
{ text: ‘CLIENT TOKEN’, dataField: ‘CLIENT_TOKEN’, width: 80, editable:false },
{ text: ‘APPROVED’, dataField: ‘APPROVED’, columntype: ‘checkbox’, width: 125, editable:true },
{ text: ‘Selected’, dataField: ”, columntype: ‘checkbox’, width: 125, editable:true }
]”;return new JavaScriptSerializer().DeserializeObject(data);
//return data;
}At $(“#jqxgrid”).jqxGrid({ columns: gridColumns }) line I am gettings aggregatesrenderer expects function error.
Hi Sethu,
I see the problem. The aggregatesrenderer property of the Grid Column expects a function, not a String.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHow do I return a return a function from webservice and not a string that’s JSON compatible
Peter,
Any updated on my question?Hi Sethu,
I suppose that you should create a Function from the returned “aggregatesrenderer” String before setting the Grid’s columns property. For creating functions, you can use the Function object – https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FFunction or may be eval – http://jsfiddle.net/DBFLF/1/
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comPeter,
We tried the above approach, but below line from jqxgrid.aggregates.js is throwing “Function not found” error.
{var c=d.aggregatesrenderer(g[d.datafield],d,b,this.getcolumnaggregateddata(d.datafield,g[d.datafield]));b.html(c)}}The actual error is “Function expected”
Hi Sethu,
If that is the error then most probably your String is not Converted to Function, because the aggregatesrenderer expects a Function.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.