SharePoint 2013: Getting lookup column values in JSLink
Hi Friends,
While working on of the development requirement related to JSLink I came across a scenario where a lookup value needed to be shown in a list view web part.
I wanted to demonstrate with following code how we can achieve to show the lookup values form single valued or multi valued lookup.
Before that I would like to show the relationship between the lists I used to show the demonstration.
I have created following two custom lists for demonstration.
First list with following column –
The content in First list will like something –
Second list having lookup column from first list –
The content in second list like following –
Following code will show how to get the single or multi valued lookup values and show.
(function () { var overrideCtx = {}; overrideCtx.Templates = {}; overrideCtx.Templates.Item = CustomPortalPageItem; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx); })(); function CustomPortalPageItem(ctx) { var html = ""; html += '<div title="' + ctx.CurrentItem.Title + '"></div><div>'+GetLookupValues(ctx.CurrentItem.Test11,"lookupValue")+'</div>'; return html; } function GetLookupValues(inputArry,originalColumnName) { var retHtml=""; if(inputArry!=null) { for(var loopcnt=0;loopcnt<inputArry.length;loopcnt++) { if (typeof(inputArry[loopcnt][originalColumnName]) != 'undefined' && inputArry[loopcnt][originalColumnName] != null) { retHtml+=inputArry[loopcnt][originalColumnName]; } } } return retHtml; }
After this it will look like following,you can then apply beautiful HTML to it.
Blog Stats
- 130,026 hits
Archives
- December 2023
- May 2021
- April 2021
- March 2021
- January 2021
- July 2020
- November 2019
- July 2019
- September 2018
- July 2018
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- June 2016
- May 2016
- March 2015
- February 2015
- December 2014
- October 2014
- July 2014
- June 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- March 2013
- February 2013
- November 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- April 2011
- February 2011
- February 2010
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |