SharePoint / PnP-JS-Core

Code moved to https://github.com/pnp/pnpjs. This repository is archived.
Other
379 stars 231 forks source link

how to add field to view? #822

Closed peterremote1980 closed 6 years ago

peterremote1980 commented 6 years ago

Hi, how to add field to view?

koltyakov commented 6 years ago

Hi @peterremote1980,

This adds a field to a view: view.fields.add('FieldInternalName')

If you need a field somewhere in the middle of the others, this can be helpful:

import { sp } from '@pnp/sp';

const list = sp.web.lists.getById(_spPageContextInfo.pageListId); // get a list whatever used to
const view = list.defaultView;

const batch = sp.web.createBatch();

const fields = ['ID', 'LinkTitle', 'Author', 'Created', 'Editor', 'Modified'];

view.fields.inBatch(batch).removeAll();
fields.forEach(fieldName => {
    view.fields.inBatch(batch).add(fieldName);
});

batch.execute().then(_ => console.log('Done')).catch(console.log);

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July, 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible, or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

peterremote1980 commented 6 years ago

thanks