Lookup with other columns
I have a Lookup-filed with the code beneeth. It works fine. Problem is, when "anothercolumn" is a lookup-field to another list in the target list istself. Then the lookup shows the text "object". Is it possible to display the text of lookup-field as column?
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},anothercolumn1,anothercolumn2&$orderby=Created desc&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},anothercolumn1,anothercolumn2&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
2. Add the fields to the item format function:
function(item) {
return '<span class="csl-option">' + item["{LookupField}"] + ' ' + item['anothercolumn1'] + ' ' + item['anothercolumn2'] + '</span>'
}
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},anothercolumn1,anothercolumn2&$orderby=Created desc&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},anothercolumn1,anothercolumn2&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
2. Add the fields to the item format function:
function(item) {
return '<span class="csl-option">' + item["{LookupField}"] + ' ' + item['anothercolumn1'] + ' ' + item['anothercolumn2'] + '</span>'
}
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
The code should be:
Item format:
The code should be:
Code: Select all
Request items:
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Lookup/Title&" +
"$expand=Lookup&$orderby=Created desc&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Lookup/Title&" +
"$expand=Lookup&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
Code: Select all
function(item) {
return '<span class="csl-option">' + item["{LookupField}"] + item.Lookup.Title + '</span>'
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 6 guests