0

I have a List which is generated and populated with Javascript. However after that I remove a column and add column 'Id' to the default view with the following code:

function fxDeleteFieldFromListView(fieldToRemove, fieldToAdd, OnSuccess, OnError) {

var ctx = new SP.ClientContext(xAppWebUrl);
var oList = ctx.get_web().get_lists().getByTitle(xListTitle);
var oView = oList.get_defaultView();
var viewFields = oView.get_viewFields();
ctx.load(viewFields);

ctx.executeQueryAsync(function (sender, args) {
    viewFields.remove(fieldToRemove);
    viewFields.add(fieldToAdd);
    oView.update();
    ctx.executeQueryAsync(OnSuccess, OnError);

}, OnError);

}

Now, column 'Id' is added AFTER the existing columns in the view, where I would like to have the column at the LEFT side of the view.

How can I reorder the columns with Javascript?

One way I could think of is remove the other 2 columns as well and then add them again after adding the 'Id' column, but I guess there should be some better way.

Thanks in advance!

1 Answer 1

1

The ViewFieldCollection has a MoveFieldTo method you can call. The first argument "Id" and the second argument would be an Int32 representing the index (position) where you want the field to appear.

https://msdn.microsoft.com/en-us/library/office/ee659514(v=office.14).aspx

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.