octobercms/october — pull request #497 by Flynsarmy (2014-07-30 06:23:32+00:00)
Title: Allow models to pass data source values to the DataGrid widget

There is currently no way to hook into the `grid.dataSource` event from a `datagrid` form field. This pull request allows your forms model to have a `getDataSourceValues` in the exact same way you can currently have a `getGridAutocompleteValues` method.

## Example Usage

```php
// In model
public function getGridDataSourceValues()
{
return $this->optionsList->toArray();
}
```

## Notes
This pull request will work provided you have only one `datagrid` field on your form. If you have more than one, the `getGridDataSourceValues` won't know which grid you're trying to get the source for. This same issue is present with the current `getGridAutocompleteValues`.

I would highly suggest figuring out how to get */modules/backend/widgets/grid/assets/js/datagrid.js* to pass the form field name to `onDataSource`, `onAutocomplete` and `onDataChanged` AJAX events and those events pass the info on to their respective widget events.