Filter foundset for unstored calculation field

I have a checkbox on a form, that has as dataprovider an unstored calculation like the following.:

function outSimbaSel( ) {
	
}

I use this as record export marker. Now, I want to filter the foundset for outSimbaSel = 1, so that my foundset only contains records with outSimbaSel = 1. A find and a foundset filter param does not seem to work.

How can I filter for the unstored calculation field?

Hi Sebastian,

Like with any unstored calcs you can’t search on them since they are in-memory (and calculated on-the-fly). When Servoy does a search/filter it will send a SQL query to the database so it will never be able to use these un-stored calcs.
You should consider unstored calculations as for display purposes only (conditional formatting, etc.) or like you do for an in-memory column (by the way shouldn’t there be a return in that function ?).
But if you really really REALLY have to search on it and you can’t make it a stored calc then you could loop over the foundset yourself (which is a pretty cumbersome solution).

Hope this explains things for you.

ROCLASI:
Like with any unstored calcs you can’t search on them since they are in-memory (and calculated on-the-fly).

Hello Robert, how can I use in-memory datasources?

ROCLASI:
You should consider unstored calculations as for display purposes only (conditional formatting, etc.) or like you do for an in-memory column (by the way shouldn’t there be a return in that function ?).

Yes I use the unstored calculation only as a virtual (in-memory) column, it is an export selection marker for a record. The user can selecte records in a table view for export, if the virtual column is selected. I need to know if the user has selected records for export, if not I need to to a dialog.

That is my problem at the moment, how to know when I need to show the dialog?

Hi Sebastian,

deezzub:
Hello Robert, how can I use in-memory datasources?

An in-memory datasource is in fact an hsqldb on the server and is defined PER session (so other users don’t see your in-mem table).
To use it you take a form without a datasource defined and in the onLoad event you create the in-memory datasource and assign it to the form like so:

function onLoad(event) {
    var _oForm = solutionModel.getForm(controller.getName()),
        _ds = databaseManager.createEmptyDataSet(0, ['myColumn1', 'anotherColumn','column3']); // create a DataSet with named columns

    // create the in-memory datasource and define the datatypes of the columns (not needed when you created the DataSet using a SQL query)
    _oForm.datasource = _ds.createDataSource('nameOfMyInMemDatasource', [JSColumn.INTEGER, JSColumn.DATETIME, JSColumn.NUMBER]); 

    // recreate the form
    controller.recreateUI();

    // now you can use the foundset as a normal foundset

}

deezzub:

ROCLASI:
You should consider unstored calculations as for display purposes only (conditional formatting, etc.) or like you do for an in-memory column (by the way shouldn’t there be a return in that function ?).

Yes I use the unstored calculation only as a virtual (in-memory) column, it is an export selection marker for a record. The user can selecte records in a table view for export, if the virtual column is selected. I need to know if the user has selected records for export, if not I need to to a dialog.

That is my problem at the moment, how to know when I need to show the dialog?

For that kind of thing I tend to use an in-memory column like you do and with a onDataChange event on it that puts the record object of the checked record in a form global (Array).
So when you check the record it gets added to the array and when you uncheck it you remove the JSRecord from the array. This way you have a a direct pointer to the checked records.

Hope this helps.

ROCLASI:
That is my problem at the moment, how to know when I need to show the dialog?
For that kind of thing I tend to use an in-memory column like you do and with a onDataChange event on it that puts the record object of the checked record in a form global (Array).
So when you check the record it gets added to the array and when you uncheck it you remove the JSRecord from the array. This way you have a a direct pointer to the checked records.

Hope this helps.

Hello - I am a new Servoy user and I am trying to do this exact thing described in the thread. Can you give code example of how to do this method, or describe in more detail?

Hi jflener,

First of all welcome to the forum, I see this is your first post.

To implement this you first need to create an un-stored calculation on your table, lets say you call it ‘mycheckbox’ (but you can call it whatever as long it is not the same as any column on this table) then your calculation looks like this:

function mycheckbox() {
    return; // this makes it an in-memory column on the table
}

On your form you create a form global that will hold all selected JSRecord objects in an array.
Now you place the field on your form (most likely a table- or list view) as a checkbox.
On this checkbox field you add a onDataChange method that manages the adding/removing of these selected records to the array.
Your code could then look like this:

/**
 * @type {Array}
 */
var _g_aSelectedRecords = new Array();

/**
 * @param {Number} oldValue
 * @param {Number} newValue
 * @param {JSEvent} event
 */
function onDataChange(oldValue, newValue, event) {
    manageSelectionArray(foundset.getSelectedRecord(), newValue);
    return true;
}

/**
 * @param {JSRecord} _rc
 * @param {Number} selected 1-select,0-unselect
 */
function manageSelectionArray(_rc, selected) {
    var _nIndex = _g_aSelectedRecords.indexOf(_rc),
        _nLength = _g_aSelectedRecords.length,
        _aTemp = new Array();

    if (selected && _nIndex == -1) {
        // don't add already selected records
        _g_aSelectedRecords.push(_rc);
    } else if (!selected && _nIndex > -1) { 
        // record exists in the array, remove it
        _aTemp = _g_aSelectedRecords.slice(0, _nIndex);
        _g_aSelectedRecords = _aTemp.concat(_g_aSelectedRecords.slice(_nIndex + 1, _nLength));
    }
}

This way you have all pointers to all selected records in the array.
And I’ve put the managing of the array outside of the onDataChange method so you can reuse it for other events as well like for when you want to select all records, etc.

Hope this helps.