title: Sort JavaScript Object by category and then by category messages
body: <p>I have 4 categories that have to be displayed in order I defined in array below. I am trying to sort by these categories and then sort messages within each category alphabetically.</p>
  
  <p>I introduced for loop in below code, but I am not sure how to add my sorted messages back in messagesL object which is the one that is being passed to rest of the code. Any hints would be greatly appreciated.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>PKG.render = function(work,PKG) {
              var data = work.details;
              var messagesL = new util.LocalDataSource(data);
              messagesL.responseSchema = {
                      resultsList: "messages",       
                      fields: [
                          "messageId",
                          "category",
                          "message"
                          ]
              };
              /*there could be more categories, ignore them*/
              var categories = ["Mentoring", "Availability", "Affordability", "Scalability", "Info"];
              var messagesColumnDefs = [
                           { key: "Id", label: "ID"},
                           { key: "category", label: "Category"},
                           { key: "message", label: "Text"}
              ];
  
              var messagesConfig = {  MSG_EMPTY: 'There are no messages to display.',
                                      MSG_ERROR: 'Error while loading table'
                                  };
              var sortedMessagesByCategory;
              for (var i = 0; i &lt; categories.length; i++) 
              {
                  var messagesByCategory;
                  for(var j = 0; j &lt; data.messages.length; j++)
                  {
                    if(data.messages[j].category === categories[i])
                        messagesByCategory.push(data.messages[j].message);
                  }
                  if(typeof messagesByCategory !== "undefined")
                      messagesByCategory.sort();
                  /*not sure how to add sorted messages back in messagesL object*/
              }          
              messagesTable = new widget.DataTable('wrmessagesTable', messagesColumnDefs, messagesL, messagesConfig);
              workResultsWidgetCollectionPush(messagesTable);
          } 
  </code></pre>