RE: Get count of all records when the view is changed
You can use fetchXml to get aggregate functions.
The following is a sample using C# code (retrieving count of emails), but you should be able to create the fetchXml string using JavaScript and Webapi to get that value:
private int RetrieveEmailCount(Guid emailId)
{
int rc = 0;
StringBuilder sb = new StringBuilder();
sb.AppendLine("<fetch distinct='false' mapping='logical' aggregate='true'> ");
sb.AppendLine(" <entity name='email'> ");
sb.AppendLine(" <attribute name='activityid' alias='email_count' aggregate='count'/> ");
sb.AppendLine(" </entity> ");
sb.AppendLine("</fetch>");
EntityCollection totalCount = service.RetrieveMultiple(new FetchExpression(sb.ToString()));
if (totalCount.Entities.Count > 0)
{
foreach (var t in totalCount.Entities)
{
rc = (int)((AliasedValue)t["email_count"]).Value;
break;
}
}
return rc;
}
So, you have two options: use the rest api or call an action to get you the results. Regardless of the option, you will need to use Ribbon Workbench to add you script to the home page.