Question

As per the title, I need to be able to update the column order by script. I've created and updated fields using Lists.UpdateList web service Method via SPServices, but can't see an option for changing the field order.

is this possible?

Thanks.

PS Just in case there's other options to achieve what I'm after, or I'm overlooking something, what I'm actually trying to achieve overall is the updating of lists and forms via script instead of the UI. So changes are repeatable and reusable and can be developed and tested on development and QA sites and then easily, accurately and reliably be applied to production sites after. This is the only thing i haven't been able to do so far.

Pas de solution correcte

Autres conseils

You can try to write your own web service or http handler and call it using ajax. I'm not able to test code on SP 2007, but it works on 13. C# reorder func:

function void ReorderColumns(SPList myList, StringCollection orderedFields)
{
    foreach (SPField field in myList.Fields)
    {
        if (!orderedFields.Contains(field.InternalName))
        {
            orderedFields.Add(field.InternalName);
        }
    }

    StringBuilder sb = new StringBuilder();
    XmlTextWriter xmlWriter = new XmlTextWriter(new StringWriter(sb));
    xmlWriter.Formatting = Formatting.Indented;
    xmlWriter.WriteStartElement("Fields");

    for (int i = 0; i < orderedFields.Count; i++)
    {
        xmlWriter.WriteStartElement("Field");
        xmlWriter.WriteAttributeString("Name", orderedFields[i]);
        xmlWriter.WriteEndElement();
    }
    xmlWriter.WriteEndElement();
    xmlWriter.Flush();
    string rpcTemplate = @"<?xml version=""1.0"" encoding=""UTF-8""?>  
        <Method ID=""0,REORDERFIELDS"">  
        <SetList Scope=""Request"">{0}</SetList>  
        <SetVar Name=""Cmd"">REORDERFIELDS</SetVar>  
        <SetVar Name=""ReorderedFields"">{1}</SetVar>  
        <SetVar Name=""owshiddenversion"">{2}</SetVar>  
        </Method>";
    string rpcCall = string.Format(
        rpcTemplate,
        myList.ID,
        SPHttpUtility.HtmlEncode(sb.ToString()),
        myList.Version);
    myList.ParentWeb.ProcessBatchData(rpcCall);
}

Where orderedFields is ordered collection of fields internal names. Try it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top