ListGrid, DataSource, and display fields

Hi, is there a way to define a new field in ListGrid such that the new field will have a name that does not exist in DataSource and the value for the new field will be some kind of combination of the fields in the DataSource?

For example, using “supplyItem” as DataSource for a ListGrid, how to add a new field in the ListGrid so that the new field is the concatenation of “itemID” and “SKU”?

Also, how to add new field (with type as “link”) in the ListGrid so that the “itemID” will be part of the URL?

Thanks.

Hi javdeveloper,

In general, you can specify fields on a ListGrid that is bound to a DataSource, and those fields will overlay the DataSource fields as described here.

You can add entirely new fields in this way as well. An example of a field whose value is calculated from two other fields is shown here.

On your other question: field type “link” is for when the entire field value is a URL. If you need to dynamically create a URL that uses one or more field values, the shortest approach is probably just to implement field.formatCellValue().

Hi, the example helps. About the “link” field, i tried with the following code and the “test” is displayed as text instead of hyperlink. Am I missing something? Thanks.

countryData = [

{
continent:“North America”,
countryName:“United States”,
countryCode:“US”,
area:9631420,
population:298444215,
gdp:12360.0,
independence:new Date(1776,6,4),
government:“federal republic”,
government_desc:2,
capital:“Washington, DC”,
member_g8:true,
article:“http://en.wikipedia.org/wiki/United_states”
},
{
continent:“Asia”,
countryName:“China”,
countryCode:“CH”,
area:9596960,
population:1313973713,
gdp:8859.0,
government:“Communist state”,
government_desc:0,
capital:“Beijing”,
member_g8:false,
article:“http://en.wikipedia.org/wiki/China”
}
];

isc.ListGrid.create({
ID: “countryList”,
width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
canEdit:false,

data: countryData,
fields:[
    {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
    {name:"countryName", title:"Country"},
    {name:"population", title:"Population",
        type:"integer",
        formatCellValue:"isc.Format.toUSString(value);"
    },
    {name:"gdp", title:"GDP ($B)",
        type:"float",
        formatCellValue:"isc.isA.Number(value) ? value.toUSString(1) : value;"
    },
    {name:"gdp_percap", title:"GDP (per capita)",
        canEdit:false,
        align:"right",
        formatCellValue: function (value, record) {
            if (!isc.isA.Number(record.gdp) || !isc.isA.Number(record.population)) return "N/A";
            var gdpPerCapita = Math.round(record.gdp*1000000000/record.population);
            return isc.Format.toUSDollarString(gdpPerCapita);
        },
        sortNormalizer: function (record) {
            return record.gdp/record.population;
        }
    },
    {
          name: "article",
          type: "link"
    },
    {
      name: "test",
      type: "link",
      formatCellValue: function (value, record) {
          return "http://www.yahoo.com"
          
        }
    }
]

})

Hi
The problem is that using a ‘link’ type field, and using ‘formatCellValue’ to implement clickable links are two separate possible approaches - the right one to use depends on your data.

If you had data where the field value was the URL you want to link to, you can use the ‘link’ type field, as demonstrated in the feature explorer.

However, since you’re dynamically assembing a URL, you probably want to use ‘formatCellValue()’ to actually write out the link HTML.
Note - you can use the Canvas helper method linkHTMLto produce this HTML rather than assembling an “<A href=…” string yourself.
So to reproduce your example - your field might look like this:

{
    name: "test",
    formatCellValue: function (value, record) {
        return countryList.linkHTML("http://www.yahoo.com");
    }
}

Thanks. That answers my question.