Namespace: grid

CSL. grid

Contains all the methods for custom scripting on a grid

Source:

Methods


.addActionCondition(options)

This function adds a condition to an action that can be done on the grid. If one of the conditions has failed, the user is not allowed to
execute the action and the button/icon/... will be hidden if defined otherwise. Be aware that keeping the button/icon/... shown will not block the functionallity!

Parameters:
Name Type Description
options Object

Specify the options for this method.

Properties
Name Type Argument Default Description
gridId String

Specify the id of the grid.

name String

Specify the unique name of the condition.

action actionEnum

Specify a value from the actions enumeration: openCreate, openUpdate, openSingleRecord, setRowAsContext, executeFunction, editList

condition function

Specify a function that checks whether the action is allowed.

functionName String <optional>

Specify the name of the function if the action is execute function.

triggerExecution Boolean <optional>
false

Specify whether execution of the conditions should be triggered immediately. Default is false.

hideRowIcon Boolean <optional>
true

Specify whether the row icon of the icon should be hidden if possible. Default is true.

hideToolbarButton Boolean <optional>
true

Specify whether the toolbar button should be hidden if possible. Default is true.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId, functionName).

  • Will throw an error when a component with the passed gridId could not be found.

  • Will throw an error if you try to add a condition with a name that already exists for that action.

Example
CSL.grid.addActionCondition({
    gridId: sourceId,
    name: "DisableEditForLockedRecords",
    action: "openUpdate",
    condition: function(rowData){ return !rowData["Locked"]; },
    triggerExecution: true,
    hideRowIcon: true,
    hideToolbarButton: true
});

.cancelInlineEdit(options)

Checks if there are changes in inline editing. If there are, they will be canceled.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId and rowNumber or rowKey).

  • Will throw an error when a component with the passed gridId could not be found.

Example
CSL.grid.cancelInlineEdit({ gridId: sourceId });

.closeInlineEdit(options)

Stops inline editing on the grid. If there are pending changes and closing is not forced, the cancel flow is used which shows a popup requesting
what you want to do with the pending changes.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Argument Default Description
gridId String

Specify the unique identifier of the grid.

force boolean <optional>
true

Specify whether you want to force closing when there are pending changes.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Example
CSL.grid.closeInlineEdit({ gridId: sourceId, force: false });

.deleteRecord(options)

This function triggers the delete function for a row on the grid.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

rowNumber Integer

Specify the number of the row. The first row is 1, the second row is 2, ...

rowKey String

Specify the row key. This is the unique value of the row.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId and rowNumber or rowKey).

  • Will throw an error when a component with the passed gridId could not be found.

  • Will throw an error if the specified function was not found.

Returns:

Returns the promise of the OFunctionService for executing the function. This promise receives notifications about the execution step. If you
want to show these notifications on the grid, it is your responsibility to add/change a notification.

Type
Promise
Example
CSL.grid.deleteRecord({ gridId: sourceId, rowNumber: 1 });

.executeFunction(options)

This function executes a list item function on the grid

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

functionName String

Specify the name of the function you want to execute.

dataItems Object

Specify the data item or array of data items you want to use for the execution of the function. Can be an array.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId, functionName).

  • Will throw an error when a component with the passed gridId could not be found.

  • Will throw an error if the specified function was not found.

Returns:

Returns the promise of the OFunctionService for executing the function. This promise receives notifications about the execution step. If you
want to show these notifications on the grid, it is your responsibility to add/change a notification.

Type
Promise
Example
CSL.grid.executeFunction({ gridId: sourceId, functionName: "Copy", dataItems: [....] });

.export(options)

Triggers the export functionality of a grid

Parameters:
Name Type Description
options object

Specify the options for this function.

Properties
Name Type Description
gridId string

Specify the unique identifier of the grid.

Source:
Returns:

A promise that is resolved when exporting has finished.

Type
Promise
Example
CSL.grid.export({ gridId: sourceId })

.getCellValue(options)

Gets the value of a cell in a row. If no row number is defined, the distinct cell values are returned.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Argument Description
gridId String

Specify the unique identifier of the grid.

viewFieldName String

Specify the name of the view field to get the value from.

rowIndex Integer <optional>

Specify the index of the row to get the value from.

Source:
Returns:

The value of the cell or an array of cell values.

Type
*
Example
var stockValue = CSL.grid.getCellValue({ gridId: sourceId, viewFieldName: "Product Stock", rowIndex: 3 });

.getPageData(options)

This function gets the data from the current page in the grid.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Argument Default Description
gridId String

Specify the unique identifier of the grid.

returnNames Boolean <optional>
false

If false, page data is returned with the view field internal names as keys.. If true, page data is returned with the view field names as keys.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Returns:

Returns the current page data objects.

Type
Array.<Object>
Example
var pageData = CSL.grid.getPageData({ gridId: sourceId, returnNames: true });
pageDate.forEach(function(pageRow){ ...... })

.getSelectedItems(options)

Gets the selected items for the given grid.

Parameters:
Name Type Description
options object

Specify the options for this function.

Properties
Name Type Argument Default Description
gridId string

Specify the unique identifier of the grid.

raw boolean <optional>
false

Specify whether the raw keys should be used. The raw keys are the internal field names instead of the labels.

Source:
Returns:

Returns an array of selected rows.

Type
Array.<object>
Example
var selectedItems = CSL.grid.getSelectedItems({ gridId: sourceId, raw: false });

.mode(options)

Gets the current mode of the grid. This is either "display" or "editing". "display" is used when the grid is just showing the data,
"editing" describes the situation where the grid is in inline edit mode

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Returns:

"display" when the grid is showing data, "editing" when the grid is in inline edit mode.

Type
string
Example
var gridMode = CSL.grid.mode({ gridId: sourceId });

.openCreate(options)

This function opens the create view that is configured on the grid.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

  • Will throw an error when the grid has no create view configured.

Returns:

Returns the unique identifier of the opened screen.

Type
String
Example
var screenId = CSL.grid.openCreate({ gridId: sourceId });

.openInlineEditing(options)

Puts the grid in inline edit mode if it isn't already. If it is already in edit mode, nothing will happen.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.
CSL.grid.openInlineEditing({ gridId: sourceId });

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.


.openSingleRecord(options)

This function opens the single record view that is configured on the grid for the passed in row. If both options.rowNumber and options.rowKey are set, options.rowNumber will be taken.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

rowNumber Integer

Specify the number of the row. The first row is 1, the second row is 2, ...

rowKey String

Specify the row key. This is the unique value of the row.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

  • Will throw an error when the grid has no single record view configured.

Returns:

Returns the unique identifier of the opened screen.

Type
String
Example
var screenId = CSL.grid.openSingleRecord({ gridId: sourceId, rowNumber: 1 });

.openUpdate(options)

This function opens the update view that is configured on the grid for the passed in row. If both options.rowNumber and options.rowKey are set, options.rowNumber will be taken.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

rowNumber Integer

Specify the number of the row. The first row is 1, the second row is 2, ...

rowKey String

Specify the row key. This is the unique value of the row.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

  • Will throw an error when the grid has no update view configured.

Returns:

Returns the unique identifier of the opened screen.

Type
String
Example
var screenId = CSL.grid.openSingleRecord({ gridId: sourceId, rowNumber: 1 });

.progress(options)

Shows or hides the progress indicator on the grid.

Parameters:
Name Type Description
options object

Specify the options for this function.

Properties
Name Type Argument Default Description
gridId string

Specify the unique identifier of the grid.

progress boolean <optional>
true

Specify whether the progress indicator should be shown or hidden.

Source:
Examples
CSL.grid.progress({ gridId: sourceId })
CSL.grid.progress({ gridId: sourceId, progress: false })

.removeActionCondition(options)

Removes a condition from a specific action

Parameters:
Name Type Description
options Object

Specify the options for this method

Properties
Name Type Argument Default Description
gridId String

Specify the id of the grid

action actionEnum

Specify an enumeration value from the actions enumeration: openCreate, openUpdate, openSingleRecord, setRowAsContext, executeFunction, editList

name String

Specify the name of the action

triggerExecution Boolean <optional>
false

Specify whether execution of the conditions should be triggered immediately. Default is false.

Source:
Example
CSL.grid.removeActionCondition({ gridId: sourceId, action: "openCreate", name: "DisableEditForLockedRecords" })

.render(options)

This function renders all the rows of the grid. When a value is being changed through custom scripting, this method should be called.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Example
// Sets the value of the field YesNo to true for all the records
 var pageData = CSL.grid.getPageData({ gridId: window.sourceId });

 for(var i = 0; i < pageData.length; i++){
     CSL.grid.setCellValue({
         rowKey: pageData[i].key,
         viewFieldName: "YesNo",
         gridId: sourceId
     });
 }

 CSL.grid.render({ gridId: sourceId });

.saveInlineEditChanges(options)

Checks if there are changes in inline editing. If there are, they will be saved. When all records have been saved successfully,
it optionally closes the inline edit mode. Only applies for grids that have Batch editing.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Argument Default Description
gridId String

Specify the unique identifier of the grid.

stayInEditMode boolean <optional>
true

Specify wheter inline edit mode should remain active after saving.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId and rowNumber or rowKey).

  • Will throw an error when a component with the passed gridId could not be found.

Example
CSL.grid.saveInlineEditChanges({ gridId: sourceId, stayInEditMode: false });

.select(options)

This functions selects the given record(s) in the multirecord view. Only records of the current page can be selected. A $scope.$apply() is needed!

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

rowNumber Integer

Specify the row number of the row(s) to select. The first row is 1, the second row is 2, ... Can be an array.

rowKey String

Specify the row key of the row(s) to select. This is the unique key value. Can be an array.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Returns:

Returns the currently selected items in the grid.

Type
Object
Example
var allSelectedItems = CSL.grid.select({ gridId: sourceId, rowNumber: [1, 3], rowKey: "P00-1" });

.selectAll(options)

This function selects all rows in the current page of the grid. A $scope.$apply() is needed!

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Returns:

Returns the currently selected items in the grid.

Type
Object
Example
var selectedItems = CSL.grid.selectAll({ gridId: sourceId });

.setCellValue(options)

Sets the value for a cell in a grid. If no rowKey or rowNumber is specified, the current editable record is taken.

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Argument Description
gridId String

Specify the unique identifier of the grid.

viewFieldName String

Specify the name of the view field.

value *

The value to set.

rowNumber Integer <optional>

Specify the number of the row. The first row is 1, the second row is 2, ...

rowKey String <optional>

Specify the row key. This is the unique value of the row.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId and rowNumber or rowKey).

  • Will throw an error when a component with the passed gridId could not be found.

Example
// Sets the value of 1 for the current record
CSL.grid.setCellValue({ gridId: sourceId, viewFieldName: "Product Category Id", value: 1);

<static> setFieldStyling(options)

Parameters:
Name Type Description
options object

The options to set styling on fields in a grid.

options.gridId

The id of the grid to find the fields on.

options.fieldNames

The field names to set the styling on.

options.condition

the style condition that returns a style object or style string.

Source:
Example
CSL.grid.setFieldStyling({
 gridId: sourceId,
 fieldNames: ['productName', 'productStock'],
 condition: function (rowData) {
   if (parseInt(rowData["productStock"]) >= 0) {
     return { "background-color": "green", color: "white" };
   } else {
     return {"background-color": "red", "color": "white"};
   } 
  }
});

.setListItemFunctionHideCondition(options)

Set the condition to hide a ListItemFunction in the grid.

Parameters:
Name Type Description
options Object

Specify the options for this method

Properties
Name Type Argument Default Description
gridId String

Specify the id of the grid

functionNames Array.<String>

The names of the functions to style.

condition function

Specify a function condition that returns a boolean. The first parameter of the function is rowData. This contains the data of the row where the key is the name of the view field

returnPromise Boolean <optional>
false

Specify whether a promise is returned. You typically return a promise when doing asynchronous actions. By doing so the performance will decrease (approx. 150 - 250ms for 100 rows).

Source:
Example
CSL.grid.setListItemFunctionHideCondition({
   gridId: sourceId,
   functionNames: ['AddToStock'],
   condition: function (rowData) {
       if (parseInt(rowData["productStock"]) >= 0) {
           return true;
       } else {
           return false;
       }
   }
});

.setListItemFunctionStyling(options)

Set the styling (color, background color, ...) of a listItemFunction field based on a condition. The condition will be executed for each row.

Parameters:
Name Type Description
options Object

Specify the options for this method

Properties
Name Type Argument Default Description
gridId String

Specify the id of the grid

functionNames Array.<String>

The names of the functions to style.

condition function

Specify a function condition that returns an object or string of CSS styling. The first parameter of the function is rowData. This contains the data of the row where the key is the name of the view field

returnPromise Boolean <optional>
false

Specify whether a promise is returned. You typically return a promise when doing asynchronous actions. By doing so the performance will decrease (approx. 150 - 250ms for 100 rows).

Source:
Example
CSL.grid.setListItemFunctionStyling({
   gridId: sourceId,
   functionNames: ['AddToStock'],
   condition: function (rowData) {
       if (parseInt(rowData["productStock"]) >= 0) {
           return "background-color:green;color:white";
       } else {
           return "background-color:red;color:white";
       }
   }
});

.setRowStyling(options)

Set the styling (color, background color, ...) of a row based on a condition. The condition will be executed for each row.

Parameters:
Name Type Description
options Object

Specify the options for this method

Properties
Name Type Argument Default Description
gridId String

Specify the id of the grid

condition function

Specify a function condition that returns an object or string of CSS styling. The first parameter of the function is rowData. This contains the data of the row where the key is the name of the view field

returnPromise Boolean <optional>
false

Specify whether a promise is returned. You typically return a promise when doing asynchronous actions. By doing so the performance will decrease (approx. 150 - 250ms for 100 rows).

Source:
Example
// Sets the value of the product name context field to Bubble gum.
 CSL.grid.setRowStyling({
     gridId: sourceId,
     condition: function(rowData) {
         if (rowData["Product Active"] === "True") {
             // Object return example.
             return { "background-color": "green", color: "white" };
         } else if (rowData["Product Active"] === "False") {
             // String return example.
             return "background-color:green; color:white";
         }
     }
 });

.setToolbarButtonHideCondition(options)

Set the condition to hide a ListItemFunction in the grid.

Parameters:
Name Type Description
options Object

Specify the options for this method

Properties
Name Type Argument Default Description
gridId String

Specify the id of the grid

functionNames Array.<String>

The names of the functions to style.

condition function

Specify a function condition that returns a boolean. The first parameter of the function is rowData. This contains the data of the row where the key is the name of the view field

returnPromise Boolean <optional>
false

Specify whether a promise is returned. You typically return a promise when doing asynchronous actions. By doing so the performance will decrease (approx. 150 - 250ms for 100 rows).

Source:
Example
CSL.grid.setToolbarButtonHideCondition({
   gridId: sourceId,
   functionNames: ['AddToStock'],
   initialValue: true,
   condition: function (gridData) {
       if (gridData.length > 10) {
           return true;
       } else {
           return false;
       }
   }
});

.setToolbarButtonStyleCondition(options, initialValue)

Set the condition to hide a ListItemFunction in the grid.

Parameters:
Name Type Argument Default Description
options Object

Specify the options for this method

Properties
Name Type Description
gridId String

Specify the id of the grid

functionNames Array.<String>

The names of the functions to style.

initialValue string | Object

The initial value to set on the toolbar button.

options.condition function

Specify a function condition that returns a boolean. The first parameter of the function is rowData. This contains the data of the row where the key is the name of the view field

options.returnPromise Boolean <optional>
false

Specify whether a promise is returned. You typically return a promise when doing asynchronous actions. By doing so the performance will decrease (approx. 150 - 250ms for 100 rows).

Source:
Example
CSL.grid.setToolbarButtonStyleCondition({
   gridId: sourceId,
   functionNames: ['AddToStock'],
   initialValue: {'background-color': 'red'},
   condition: function (gridData) {
       if (gridData.length > 10) {
           return {'background-color': 'red'};
       } else {
           return {'background-color': 'green'};
       }
   }
});

.unselect(options)

This functions unselects the given record(s) in the multirecord view. Only records of the current page can be unselected. A $scope.$apply() is needed!

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

rowNumber Integer

Specify the row number of the row(s) to select. The first row is 1, the second row is 2, ... Can be an array.

rowKey String

Specify the row key of the row(s) to select. This is the unique key value. Can be an array.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Returns:

Returns the currently selected items in the grid.

Type
Object
Example
var allSelectedItems = CSL.grid.unselect({ gridId: sourceId, rowNumber: [3], rowKey: "P00-1" });

.unselectAll(options)

This function unselects all rows in the current page of the grid. A $scope.$apply() is needed!

Parameters:
Name Type Description
options Object

Specify the options for this function.

Properties
Name Type Description
gridId String

Specify the unique identifier of the grid.

Source:
Throws:
  • Will throw an error if any required input field is not set (gridId).

  • Will throw an error when a component with the passed gridId could not be found.

Returns:

Returns the currently selected items in the grid.

Type
Object
Example
var selectedItems = CSL.grid.unselectAll({ gridId: sourceId });