Saving Column order and sorting

Questions and answers for designing and implementing forms in Servoy

Saving Column order and sorting

Postby eKelman » Mon Jan 16, 2012 7:46 pm

hi,

Is there a way to preserve column order in the application?

The situation is like this. We want to have the ability for the user to shuffle columns around, and sort on columns, and then save that shuffling and ordering so that each user can view the columns in their own way.

Our forms are not created through solution model.

Has anyone out there been able to do this before? And if you have been successful, can you please provide me some information on how to achieve this.


Sorry in addition to this, can someone tell me how to get the users current order and widths of columns. I am unable to get the correct values after a user has shuffled and adjusted columns.

Thank you
Ernest
Kelman Technologies
eKelman
 
Posts: 52
Joined: Tue May 12, 2009 9:09 pm

Re: Saving Column order and sorting

Postby omar » Tue Jan 17, 2012 4:51 pm

Hi Ernest,

I did some experiments and the following code worked for me. I added a saveLocation method to globals as follows:

Code: Select all
function saveLocation(_cFormName){
   var _oForm = forms[_cFormName];
   var _oElement;
   var _cSaveFile = "";
   var _nLocationX = 0;
   var _nLocationY = 0;
   var _lSuccess = false;
   for (var i=0; i < _oForm.elements.length; i++)
   {
      _oElement = _oForm.elements[i];
      _nLocationX = _oElement.getLocationX();
      _nLocationY = _oElement.getLocationY();
      _cSaveFile = _cSaveFile + _oElement.getName() + "|" + _nLocationX + "," + _nLocationY + "\n";
   }
   _cSaveFile = _cSaveFile + " \n "; // avoid infinite loop on the last line
   _lSuccess = plugins.file.writeTXTFile(_cFormName+"_loc.mem", _cSaveFile);
}


and a restoreLocation like this:

Code: Select all
function restoreLocation(_cFormName){
   var _oForm = forms[_cFormName];
   var _oFile = plugins.file.convertToJSFile(_cFormName+"_loc.mem");
   try {
      if (_oFile.exists()){
         var _cSaveFile = plugins.file.readTXTFile(_cFormName+"_loc.mem");
         var _nPos1, _nPos2, _nPos3, _nLocX, _nLocY;
         var _cElementName;
         while ( _cSaveFile.indexOf("|") > -1) {
            _nPos1 = _cSaveFile.indexOf("|")
            _nPos2 = _cSaveFile.indexOf(",")
            _nPos3 = _cSaveFile.indexOf("\n")
            _cElementName = _cSaveFile.substr(0,_nPos1);
            _nLocX = utils.stringToNumber(_cSaveFile.substr(_nPos1+1, _nPos2-1));
            _nLocY = utils.stringToNumber(_cSaveFile.substr(_nPos2+1, _nPos3-1));
            _cSaveFile = _cSaveFile.substr(_nPos3+1);
            _oForm.elements[_cElementName].setLocation(_nLocX, _nLocY);
         }
      }
   }
   catch(_oException) {
      application.output(_oException.message);
      _oFile.deleteFile();
   }
}


to trigger the saving you could add a call in the onHide event:

Code: Select all
function onHide(event) {
   globals.saveLocation(controller.getName());
   return true
}


and to trigger restoring on startup add a call to the onShow:

Code: Select all
function onShow(firstShow, event) {
   if (firstShow){
      globals.restoreLocation(controller.getName());
   }   
}


This works for any ListView form. You may want to add some more validation code.

To save and restore sorting info use JSFoundset.getCurrentSort() and JSFoundset.Sort().
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 377
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands

Re: Saving Column order and sorting

Postby eKelman » Mon Mar 26, 2012 10:23 pm

Thanks Omar,

I took some of your suggestions and got our functionality to work.

Cheers
Ernest
Kelman Technologies
eKelman
 
Posts: 52
Joined: Tue May 12, 2009 9:09 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 5 guests

cron