Skip to content

Unable to set ColumnWidth via ListViewXml for List ViewΒ #1596

Description

@jpalo

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);

Activity

  1. added
    help wanted
    area: model πŸ“
    on Jan 30, 2025
  2. jansenbe commented on Jan 30, 2025

    @jansenbe
    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

  3. added
    bug
    on Jul 15, 2026
  4. added theissue type on Jul 15, 2026
  5. Guflly commented on Aug 5, 2026

    @Guflly
    Contributor

    I would like to work on this.

  6. added and removed
    help wanted
    on Aug 5, 2026
  7. Adam-it commented on Aug 5, 2026

    @Adam-it
    Member

    I would like to work on this.

    Perfect πŸ‘ All yours

  8. added a commit that references this issue on Aug 5, 2026
    3f81b60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: model πŸ“bugwork in progress

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions