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
omar
January 17, 2012, 2:51pm
2
Hi Ernest,
I did some experiments and the following code worked for me. I added a saveLocation method to globals as follows:
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:
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:
function onHide(event) {
globals.saveLocation(controller.getName());
return true
}
and to trigger restoring on startup add a call to the onShow:
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().
Thanks Omar,
I took some of your suggestions and got our functionality to work.
Cheers