Hi,
I'm trying to display some json data in the grid (2017.1). I've set the grid up as follows:
$("#jobs").igGrid({ dataSource: gdata, width: "100%", renderCheckboxes: true, autoGenerateColumns: false, columns: [ { key: "Haulier", headerText: "Company", dataType: "string" }, { key: "Job", headerText: "Job", dataType: "string", unbound: true, template: jobTemplate }, { key: "JobType", headerText: "Job Type", dataType: "string" }, { key: "CollectionFrom", headerText: "Collection", dataType: "string" }, { key: "DeliveryTo", headerText: "Delivery", dataType: "string" }, { key: "DateAssigned", headerText: "Assigned to you", dataType: "date", format: "yyyy-MM-dd HH:mm" }, { key: "AssignedTo", headerText: "Driver", dataType: "string" } ], features: [ { name: "Filtering" }, { name: "Paging", showPageSizeDropDown: false }, { name: "Sorting" }, { name: "Selection", inherit: true } ] });
jobTemplate is defined as < a href="/SupplierPortal/Itinerary/Itinerary/${ItineraryID}">${Reference}< /a>
(spaces added to avoid being interpreted as HTML)
So I want a link that ends in the value of the ItineraryID fields from the json, and displays the Reference field on the page. The column on the grid remains blank though (the other columns are populated okay). I presume I'm not specifying the column template correctly - can anyone tell me what it should be?
The json looks like this (but with more rows):
[{"ItineraryID":"b7a46736-4a06-4cf5-94e7-5a2b67c1ad3e","Haulier":"Test","Reference":"RX356562","JobType":"Collection","CollectionFrom":"JGRG233396/1: Bousbecque 59166","DeliveryTo":"","DateAssigned":"2016-10-07T13:11:00","AssignedTo":null}]
Moved to the grid forum
Hello Kevin,
Define the columns you want to use into the columns definitions and if you don't need to display them set them hidden:
{ key: "Reference", headerText: "Reference", dataType: "string", hidden: true },
{ key: "ItineraryID", headerText: "ItineraryID", dataType: "string", hidden: true },
Change the template option to: template: $("#jobTemplate").html()
Please review the attached sample, where those modifications are applied and let us know if you have further questions.
You're welcome, Kev!
Thanks Deyan, that makes sense. Always interesting to see what is going on behind the scenes
Kev
Hi Kevin,
I'm glad it helped!
Actually the grid data source is making transformations and it strips the column of the data you are not using(not having in columns definition).
By default localSchemaTransform is true, but you can set it to false and not having the need to define additional hidden columns. But my recommendation is to leave the columns hidden and allow the data source transformations.
Thanks Deyan, that's done the trick. So to use a field in a template it must also be present as a column. Is this something I missed in the documentation? If not then I'd say it would be worth adding a note about it to the "Creating a basic column template" documentation page (and probably to the row template equivalent, as one of the things I tried when I was investigating it was using row templates, and they have the same behaviour)
Kevin