0
votes

I have a list with multiple views (around 15 views). How can I add a same set of buttons to all the views below the page title and above list web part? I have SharePoint designer. I have used content editor web part, but I need to add it to all view aspx pages and add the same set of buttons. Any better solutions?

Thanks Venky

1

1 Answers

0
votes

You could read the existing views with javascript (JSOM) to retrieve all the existing views on the specified list.

In the OnQuerySucceed function while looping through the views you could generate a button and add it the DOM. For example in your content editor add a element and push the buttons in their.

var viewCollection = null;

function runCode() {

var clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
    var web = clientContext.get_web();

    var listCollection = web.get_lists();
    var list = listCollection.getByTitle("Tasks");
    this.viewCollection = list.get_views();

    var viewInfo = new SP.ViewCreationInformation();
    viewInfo.set_title('MyView');
    this.viewCollection.add(viewInfo);

    clientContext.load(this.viewCollection);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}

function onQuerySucceeded() {
    var viewInfo = 'Tasks list current views: \n\n';
    var viewEnumerator = this.viewCollection.getEnumerator();
    while (viewEnumerator.moveNext()) {
        var view = viewEnumerator.get_current();
        viewInfo += view.get_title() + '\n';
    }
    alert(viewInfo);
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}