jQWidgets Forums

jQuery UI Widgets Forums Grid Cellformat based on another column value

This topic contains 3 replies, has 2 voices, and was last updated by  Hristo 8 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • xixo
    Participant

    Hello.

    I’m trying to put a dynamic cell formating based on another colum value. Some rows I want to display currency, another ones percentage.

    This is what I tried so far:

    var dataAdapter = dataAdaptersourceanlevofam;
        var cellclassname = function (row, column, value, data) {
            if (data.nome != "") {
                return "grayline";
            };
        };
        var cellformat = (function (row, column, value, data) {
            if (data.year!= "Evo")
            {
                return "c0";
            }
            else
            {
                return "p2";
            }
        })();
        $("#jqxgridanl").jqxGrid({
            source: dataAdaptersourceanl,
            theme: 'Metro',
            height: 600,
            width: '100%',
            sortable: true,
            columnsresize: true,
            showaggregates: false,
            showstatusbar: true,
            statusbarheight: 25,
            altrows: false,
            showtoolbar: true,
            columns: [
                        { text: 'Family', dataField: 'family', width: 240, sortable: false, cellclassname: cellclassname },
                        { text: 'Year', dataField: 'year', width: 50, sortable: false, cellclassname: cellclassname },
                        { text: 'M1', dataField: 'm1', width: 110, align: 'right', cellsalign: 'right', sortable: false, cellclassname: cellclassname, cellsformat: cellformat }
            ]
        });

    But when I run this code I get
    “Uncaught TypeError: Cannot read property ‘year’ of undefined”

    The cellclassname function is working fine.

    Any pointers?


    Hristo
    Participant

    Hello xixo,

    Only string could set on cellsformat, with possible values that could see in our API Documentation.
    About that you want to achieve could use cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) { //Do Something }
    Please, take a look this example:
    http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/defaultfunctionality.htm?light

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com


    xixo
    Participant

    Thanks for the tip.

    Just put it on cellsrenderer, like this:

    var dataAdapter = dataAdaptersourceanlevofam;
        var cellclassname = function (row, column, value, data) {
            if (data.nome != "") {
                return "grayline";
            };
        };
        $("#jqxgridanl").jqxGrid({
            source: dataAdaptersourceanl,
            theme: 'Metro',
            height: 600,
            width: '100%',
            sortable: true,
            columnsresize: true,
            showaggregates: false,
            showstatusbar: true,
            statusbarheight: 25,
            altrows: false,
            showtoolbar: true,
            columns: [
                        { text: 'Family', dataField: 'family', width: 240, sortable: false, cellclassname: cellclassname },
                        { text: 'Year', dataField: 'year', width: 50, sortable: false, cellclassname: cellclassname },
                        { text: 'M1', dataField: 'm1', width: 110, align: 'right', cellsalign: 'right', sortable: false, cellclassname: cellclassname, cellsrenderer: function (row, column, value) {
                                var valor = $("#jqxgridanlevofam").jqxGrid('getcellvalue', row,'ano');
    
                                if (valor != 'Evo') {
                                    value = $.jqx.dataFormat.formatnumber(value, 'c0');
                                }
                                else 
                                {
                                    value = $.jqx.dataFormat.formatnumber(value, 'p2');
                                }
    
                                return '<span style="margin: 4px; float: right;">' + value + '</span>';}
            ]
        });

    But now I’ve got another problem, which is the currency format.
    Usually I put:

    var localizationobj = {};
    localizationobj.currencysymbol = " €";
    localizationobj.currencysymbolposition = "after";
    $("#jqxgridanl").jqxGrid('localizestrings', localizationobj);

    after creating the grid, but now it doesn’t work as it allways puts the “$” character.

    Thanks.


    Hristo
    Participant

    Hello xixo,

    Could you try to use whole custom logic. You could set directly desirable string (for example: value = 12€ or value = 12.12%).

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.