Author Topic: Error manipulating strings in render function  (Read 2819 times)

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Error manipulating strings in render function
« on: February 10, 2016, 08:23:53 pm »
Hi,

I'm looking to render a column output but I get the error "dt is undefined" if I write:
Code: [Select]
render: function( ui ){ var dt = ui.text; return dt.substring(0,8); }
or the error: "ui.text is undefined" if I write:
Code: [Select]
render: function( ui ){ ui.text.substring(0,8); }
but I have no error if I write:
Code: [Select]
render: function( ui ){ ui.text; }or
Code: [Select]
render: function( ui ){ var dt = 'abcd1234567890'; return dt.substring(0,4)+':'+dt.substring(4,8); }
Thank you

Code: [Select]
$(function () {
        var data = [[1, 'Exxon Mobil', '20160219.001', '339,938.0', '36,130.0'],
            [2, 'Wal-Mart Stores', '20160210.002', '315,654.0', '11,231.0'],
[39, 'Royal Dutch Shell', '20160210.001', '306,731.0', '25,311.0'],
[19, 'Crédit Agricole', '20160213.001', '110,764.6', '7,434.3'],
[20, 'American Intl. Group', '20160228.001', '108,905.0', '10,477.0']];

        var obj = {
            scrollModel: {autoFit: true},
            height: 400,
            colModel: [
                { title: "Rank", width: 100, dataType: "integer" },
                { title: "Company", width: 200, dataType: "string"},

// { title: "Date", width: 100, dataType: "string", render: function( ui ){ return ui.rowData[2].substring(0,4); } },
                // { title: "Date", width: 100, dataType: "string", render: function( ui ){ var dtx = ui.rowData[ui.rowData.rowIndx]; return dtx.substring(0,4); } },
                // { title: "Date", width: 100, dataType: "string", render: function( ui ){ return ui.rowData[ui.rowData.rowIndx].substring(0,4); } },
                // { title: "Date", width: 100, dataType: "string", render: function( ui ){ return ui.rowData[ui.rowData.rowIndx].substr(0,4) } }, //ERROR ->

// { title: "Date", width: 100, dataType: "string", render: function( ui ){ var dt = 'abcd1234567890'; return dt.substring(0,4)+':'+dt.substring(4,8); } },
{ title: "Date", width: 100, dataType: "string", render: function( ui ){ var dt = ui.text; return dt.substring(0,4)+':'+dt.substring(4,8); } },

                { title: "Revenues ($ millions)", width: 180, dataType: "float" },
                { title: "Profits ($ millions)", width: 180, dataType: "float" }
            ],
            dataModel: {
                data: data,
                sortIndx: 1,
                sortDir: "up"
            }
        };

        $("#grid_custom_sorting").pqGrid(obj);
    });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Error manipulating strings in render function
« Reply #1 on: February 10, 2016, 08:48:21 pm »
ui.text and ui.rowData.rowIndx are incorrect as text is not a property of ui and rowIndx is not a property of rowData.

The cell value is ui.cellData

All the properties of ui are mentioned in the API: http://paramquery.com/pro/api#option-column-render

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Error manipulating strings in render function
« Reply #2 on: February 10, 2016, 09:16:00 pm »
Solved

Thank you