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 · 0 comments
Open
1 task done

Unable to set ColumnWidth via ListViewXml for List View #1596

jpalo opened this issue Jan 2, 2025 · 0 comments

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant