Sorting in List Views

This post won't contain any code. I just want to share some basic and well-known things and point to one weird behavior I've found.
So Sorting... or Ordering... or <OrderBy>.
You can add sorting to list view in List Settings -> Edit View in Sort section. There you can add 1 or 2 columns to sort and sorting order. Items will be sorted by the first selected column and then by the second one if they have the same value in the first column.
When user works with the view (browse list items) he can add additional sorting through UI by clicking a header of any column (well, almost any - you can't sort by Multi Lookup columns, User and Group columns with allow multiple selection). In that case selected column will be added as the first item of sorting chain. That means that items will be sort by:

  1. Column that is added by user through List View UI
  2. Columns that were added in Sort section of Edit View page.
This behavior looks good and clear.

If user works with Task list (or descendant of task list) and adds sorting by clicking a column's header (or in context menu of a column's header) all sorting columns that were added to View will be removed. Moreover, sorting by Title will be added. And as a result items will be sort by:
  1. Column that is added by user through List View UI
  2. Title column
I don't know why it is so, but it is so... 
Don't miss that fact if you're implementing some features that are dependent on sorting (for example, custom pagination).
If you know some other exceptions to the rule please share them in comments.

Have fun!


Remove DOM event handlers on SharePoint Page

I won't write a lot of words in here...
Environment: SP Online, Publishing Portal
Problem: jQuery.off(), jQuery.unbind(), element.removeEventHandler didn't work so we need to find a way to remove event handlers.


A Little Bit of Self-Advertisement

Sharepointalist recently released a new product – List Booster. It’s a new generation SharePoint add-in, created using JavaScript and CSS only – no server-side code – works for both SharePoint Online (Office 365) and SharePoint 2013. List Booster enhances out of the box SharePoint user experience enabling user to do the following, when working with lists and document libraries:
  • resize columns (including auto-size by double click);
  • change of font styles, text alignment, color and background for columns and headers;
  • real paging (showing total amount of pages and clicking on the page number same way as in Google), visible both on top and bottom of the list;
  • table styles color schemes – same as you have in Microsoft Excel or Word;
  • it all works both in regular view and in quick edit mode.
All those features are very intuitive and easy to use by the end users. Helps a lot with the user adoption within organization and increases performance when working with large lists and document libraries.

You can check out short video about the product at http://www.spbooster.com

Performace of querying items in lists and libraries

Some time ago I was working on project where I needed to query items from several lists and document libraries (each list and library contained 200+ items). I needed to display Title and Url fields from lists and file name and file url from document libraries.
My first code worked too long and I've started to think about increasing the performance of queries.
And here are the things that helped me to increase speed in several times:

  1. Use <ViewFields> inside query instead of Include(...) inside ClientContext.Load()
  2. Use FileRef and FileLeafRef fields instead of File field (which is an object with several properties in it).

That's all. These two changes helped me a lot. And the customer is happy about the performance they have.
Have fun!


Flie Not Found exception when calling ExecuteQuery in Client Side Object Model.

Today I've got an exception in my Provider-Hosted App. The message was "File not found" and nothing more...
But I do not work with files, document libraries, attachments or any other resources that can be received as a file in that app. That why such a message was very unexpected.
After debugging I understand where was a problem: I was trying to open Web with absolute Url, not relative.
So, if you have the same exception check your Urls.
Have fun!

Close Modal Dialog from App page in Provider-Hosted App

Sometimes there is a necessity to show some App page in Modal Dialog.
For example, show some settings on custom action click.
It is simple to show the dialog, but standard approach of closing it doesn't work because the App and SharePoint site can be hosted on different domains. And we can't just commit popup from cross-domain frame document.
To close the dialog you can use HTML5 postMessage API.


JavaScript Rating control to use outside list views

There are a lot of tasks when you have to display information from list item in web part or on the page without list view.
For example, you have to create a web part to display any kind of media on the page. And this media contains a Rating field.
For such situations I've created a JavaScript control to render Rating Field outside list views. The control is based on RateIt jQuery plugin.
So no more words, let's have some code.


Fixing executeQueryAsync "The file _list_or_something_else_ has been modified by _user_ on _date_" exception

The reason for the exception is the update of some entity in two separate queries that are executed at the same time.
For example, you're changing list item title and description. But you're not grouping these operations but executing them separately. In such situation you'll get the described error.