Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<skuidpage showsidebar="true" showheader="true" tabtooverride="Opportunity">
<model id="SortOrders" limit="100" query="true" createrowifnonefound="false" sobject="Sort_Order__c">
<field id="Sort_Order__c"/>
<field id="Skuid_Page__c"/>
<field id="Skuid_Page__r.Name"/>
<field id="Model_Id__c"/>
<condition type="userinfo" value="" field="OwnerId" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
<condition type="fieldvalue" value="Opportunities_withSavedSortOrder" enclosevalueinquotes="true" field="Skuid_Page__r.Name"/>
<model id="Opportunity" limit="100" query="false" createrowifnonefound="false" sobject="Opportunity">
<field id="Name"/>
<field id="CreatedDate"/>
<field id="LeadSource"/>
<field id="StageName"/>
<field id="OwnerId"/>
<field id="Owner.Name"/>
<pagetitle model="Opportunity">
<skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Opportunity" mode="read">
<field id="Name" allowordering="true"/>
<field id="LeadSource" allowordering="true"/>
<field id="StageName" allowordering="true"/>
<field id="OwnerId" allowordering="true"/>
<field id="CreatedDate" allowordering="true"/>
<action type="edit"/>
<action type="delete"/>
<massactions usefirstitemasdefault="true">
<action type="massupdate"/>
<action type="massdelete"/>
<view type="standard"/>
<jsitem location="inline" name="Load sort order" cachelocation="false" url="">(function(skuid){
var $ = skuid.$;
// Do NOT try to auto-sort these Models
var modelsToIgnore = {
var SortOrders = skuid.model.getModel('SortOrders');
// See if we have a saved Sort Order for the Opportunity model
var modelsToLoad = [],
uniqueModelsToLoad = {};
var GetSortOrderForModel = function(model){
var target;
if ( {target = so;return false;}
if (!target){
target = SortOrders.createRow();
Sort_Order__c: model.orderByClause,
OwnerId: skuid.utils.userInfo.userId
return target;
if ( &amp;&amp; {
var modelId = so.Model_Id__c;
if (modelId) {
var model = skuid.model.getModel(modelId);
if (model) {
console.log('found a corresponding Model, applying Sort Order')
// if we found a Model, apply our Sort Order to it
model.orderByClause = so.Sort_Order__c;
console.log('model order by clause: ' + model.orderByClause);
console.log('Sort Order: ' + so.Sort_Order__c);
if (modelId in uniqueModelsToLoad) {}
else {
} else {
// Create a default Sort Order for all Models
// NOT being sorted by our saved sorts
var modelId =;
if (modelId in uniqueModelsToLoad) return true;
else {
if (model.orderByClause) {
// Add this Model to the list of Models to load,
// if it does not yet have any data in it
if ( &amp;&amp; !(modelId in modelsToIgnore)){
if (modelsToLoad.length) {
// NOW, setup some listeners on all our Models
// so that whenever they are updated,
// we save our Sort Orders.'models.loaded',function(loadResult){
if (model.orderByClause){
var so = GetSortOrderForModel(model);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment