No announcement yet.
  • Filter
  • Time
Clear All
new posts

    What data type should I use for a MultiComboBoxItem

    I have a data source with a "text" field that has its values separated with "|" to store user roles (to keep the database simple I have not used a separate table to link roles to users). The column's value looks like this: "|admin|management|sales|". When retrieving the data for a MultiComboBoxItem, I return the values as array from the server (thus ["admin", "management", "sales"]). I run into these two "issues":

    1) Using a optionDataSource like this:

     "cacheData": [
        { "code": "finance", "name": "Finance" },
        { "code": "readonly", "name": "Read-only" },
        { "code": "management", "name": "Management" },
        { "code": "system", "name": "System" },
        { "code": "sales", "name": "Sales" }
    "clientOnly": true,
    "fields": [
        { "name": "code", "primaryKey": true, "title": "Code", "type": "text" },
        { "name": "name", "title": "Name", "type": "text" }
      "ID": "ROLE_ENUM"
    I need to filter certain roles out based on the current user. Before, I used a SelectItem (because only one role could be linked to an user) and I used this to filter out certain roles:

      optionDataSource: "ROLE_ENUM",
      pickListCriteria: {
        fieldName: 'code',
        operator: 'inSet',
        value: <an array of valid roles created based on a condition>
    This seems to be impossible with MultiComboBoxItem. I therefore created a valueMap with the filtered values and this seems to work. Just checking if this is the right approach.

    2) The values can be selected and saved: SmartClient sends an array, my application stores a string (with the "|" symbols), but returns the saved record using an array. Strangely, the MultiComboBoxItem now shows one button with the value "finance,sales" instead of two separate buttons. After that, saving false because unknown values are passed. Is the "text" data type incorrect? Should I return a string with comma's separated?
    Last edited by wallytax; 10th Feb 2021, 01:18.

    When using a field in the form that does not exist in the data source, it works! Is the data source field type "text" the problem?

    When I leave that out, it works! If I try to overrule at form item level (with null, "any" or ""), it does not work.
    Last edited by wallytax; 10th Feb 2021, 01:16.


      And a final question about displaying the roles in the corresponding grid. I've managed to do this, by defining this method on the grid field:

      formatCellValue: function(value) {
        return (role) {
          return ROLE_ENUM.getCacheData().find('code', role).name
        }).join(', ');
      Is this the right way or is there an easier way?
      Last edited by wallytax; 10th Feb 2021, 01:36.


        See DataSourceField.multiple - you want to set this on your field to indicate that it is array-valued. That's why this worked without a DataSource - it was because your DataSource definition is incorrect.

        Once you have correctly configured the field as multiple, you will see a number of behaviors automatically kick in regarding formatting, editing, etc.

        As far as your formatCellValue implementation, that's fine but you should just create a map from role codes to role names rather than running a find() on the complete dataset every time the cell is formatted.