0

I'm trying to fetch the values from a sharepoint list view and display it in a table dynamically. In doing so, I require both the column internal names to fetch the items from the list and column display name to set the header of the table.

I'm able to fetch the internal names of the columns in that list view using below code

await sp.web.lists.getByTitle(listName).views.getByTitle(viewName).get().then(async (data: any) => {});

Using the internal names, I'm able to fetch the records from that list as well. The only thing remaining now is, how do I fetch the column display names so, that I can set those value in the header of the table? Can I do it using the already fetched internal names?

1
0

I think 'View' or 'ViewFields' does not contain info about displayname. So i suggest you retrieve them in anohter request:

const View = await sp.web.lists.getByTitle('listname').views.getByTitle('All Items')(); 

const fields: IViewFields = await sp.web.lists.getByTitle('listname').views.getByTitle('All Items').fields();
console.log("field: ", fields);

let internames: string[] = (fields as any).Items;
let filterstring: string = internames.map(x => `(InternalName eq '${x}')`).join(` or `);
console.log("filterstring: ", filterstring);

const displayanmes = await sp.web.lists.getByTitle('listname').fields.filter(filterstring).select('InternalName', 'Title').get();
console.log("displayanmes: ", displayanmes);

Result:

enter image description here

BR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.