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.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
  • aggregates in dynamic columns #33074

    Sethu
    Participant

    Hi,
    I am creating my grid dynamically (Columns created) from server.
    How can I apply aggregates rendering on specific columns.

    aggregates in dynamic columns #33087

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    aggregates in dynamic columns #33093

    Sethu
    Participant

    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.

    aggregates in dynamic columns #33106

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    aggregates in dynamic columns #33109

    Sethu
    Participant

    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.

    aggregates in dynamic columns #33121

    Peter Stoev
    Keymaster

    Hi Sethu,

    I see the problem. The aggregatesrenderer property of the Grid Column expects a function, not a String.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    aggregates in dynamic columns #33163

    Sethu
    Participant

    How do I return a return a function from webservice and not a string that’s JSON compatible

    aggregates in dynamic columns #42353

    Sethu
    Participant

    Peter,
    Any updated on my question?

    aggregates in dynamic columns #42381

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    aggregates in dynamic columns #42800

    Sethu
    Participant

    Peter,
    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)}}

    aggregates in dynamic columns #42824

    Sethu
    Participant

    The actual error is “Function expected”

    aggregates in dynamic columns #43487

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.