Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set ColumnWidth via ListViewXml for List View #1596

Open
1 task done
jpalo opened this issue Jan 2, 2025 · 1 comment
Open
1 task done

Unable to set ColumnWidth via ListViewXml for List View #1596

jpalo opened this issue Jan 2, 2025 · 1 comment
Labels
area: model 📐 Related to the core SDK models help wanted Extra attention is needed

Comments

@jpalo
Copy link

jpalo commented Jan 2, 2025

Category

  • Bug

Describe the bug

When setting column width of a List View, setting ListViewXml of a view doesn't seem to persist, but instead the list view is reset to default. By "reset" I mean that if I have added field to the view earlier, it is also removed, so the View resets to default fields too. This works when doing via PnP JS, but not when using PnP Core.

Steps to reproduce

// create list
var list = await destinationSiteContext.Web.Lists.AddAsync(listName, ListTemplateType.DocumentLibrary);

var defaultView = list.Views.First();

// get existing ListViewXml, add ColumnWidth definition for one field
var defaultViewXml = defaultView.ListViewXml
    .Replace(
        "</View>",                                        
        "<ColumnWidth><FieldRef Name=\"Modified\" width=\"370\" /></ColumnWidth></View>"
    );

// save changes to view
defaultView.ListViewXml = defaultViewXml;
await defaultView.UpdateAsync();

Expected behavior

ListViewXml would contain the ColumnWidth definition and view in UI would also have wide Modified column.

Environment details (development & target environment)

  • SDK version: 1.14.0
  • SDK used in: Azure Function
  • Framework: .NET 8
  • Tooling: Visual Studio 2022

Additional context

Using PnPJs in SPFx web part it works:

let lv: any = await list.defaultView.select('ListViewXml')();
let lvXml: string = lv.ListViewXml.replace(
            '</View>',
            `<ColumnWidth><FieldRef Name="Modified" width="370" /></ColumnWidth></View>`);

await list.defaultView.setViewXml(lvXml);
@jansenbe jansenbe added help wanted Extra attention is needed area: model 📐 Related to the core SDK models labels Jan 30, 2025
@jansenbe
Copy link
Contributor

@jpalo : In PnPJS the SetViewXml methodf is used to set the view whereas PnP Core SDK sets the ListViewXml property. Check the internal code it seems that SetViewXml is setting some internal property next to setting the ListViewXml property, so most likely this can be fixed by adding a method to PnP Core SDK for this in https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/View.cs and https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core/Model/SharePoint/Core/Public/IView.cs.

Would be great if you can do that, alternatively you can unblock yourselves by making the API call using our built in custom API calling feature: https://pnp.github.io/pnpcore/using-the-sdk/basics-customapirequests.html#making-a-custom-spo-rest-request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants