Migrating from v2 to v3
Table of contents:
- Quick summary
- Package new name
- Composer as the suggested way of installation
- Change in Assets Folder Location
- PHP Configuration Changes
- Library API Changes
- New Features
- Functionality Changes
- Javascript Changes
- JavaScript Events
- JavaScript Configuration Changes
In short the upgrade from version 2 to version 3 should be very straight forward. Since we haven't changed a lot the API of the library, you should be able to upgrade without any problems. There are 3 main areas that you should be aware of:
- The configuration file has changed, so it is better to copy the new configuration file rather than just updating the old one. It is easier and faster.
- The composer package name has changed from
grocerycrud/enterprisetogrocery-crud/enterprise. The library name though is still the same. For example, you can call$crud = new GroceryCrud($config, $database);as before. - The JavaScript events has changed a lot! So if you were using the JavaScript events then please read the JavaScript changes below. If not, then you can skip this part.
The biggest change that you will actually notice is the package new name for Composer.
The package previously known as:
grocerycrud/enterprise
has been renamed to:
grocery-crud/enterprise
with the inclusion of a dash in the name.
The documentation now recommends using Composer as the primary method for installation.
In the past we were mainly suggesting to copy the library and the assets folders manually. Currently, we advise users to use Composer as the preferred method instead. This is because composer is a popular dependency manager for PHP and is widely used in the PHP community anyway!
It makes it easy to manage the package and its dependencies, ensuring that everything is properly installed and configured for use. Using composer also makes it easier to update the package when new versions are released, as it handles all the necessary dependencies and file management automatically.
The assets folder for our installation packages has been moved from public/grocery-crud to public/vendor/grocery-crud.
This change was inspired by the assets folder structure used by
Laravel Public Assets and
was made to provide a more familiar structure for the public assets folder.
Breaking changes:
- The argument
skinis now used for ‘light’ and ‘dark’ skin, and we use thethemefor the configuration of the theming. For example:’theme’ ⇒ ‘bootstrap-v5’,’skin’ ⇒ ‘dark’
Configuration arguments that has been removed:
hash_in_urlhas been removed. Replaced byurl_history.- The configuration argument
text_editor_typehas been removed. We are currently using React Quill as our text editor. We made this change since we have plans for the future of being able to add your favorite text editor more easily and not to rely on pre-configured text editors. - PHP Configuration
date_formatis removed. no more date configuration from the backend (e.g. UK-date or US-date). The date will be transformed into the frontend from the language and with the locale by trying to guest the best possible mapping. We appreciate any feedback on date formatting as it is an area that we are always looking to improve. - PHP Configuration
remember_quick_searchis removed as we always remember our search values into the frontend
New configuration arguments:
-
Introducing new configuration argument
url_historyinstead ofhash_in_urlas the functionality of the URL has been modified. Theurl_historyis a boolean value that can be set totrueorfalse. The new URL is more user-friendly, such asadmin/customers/edit/123instead ofadmin/customers#/edit/123. The default value forurl_historyisfalse, as this may require additional route configuration in the framework being used. -
Introducing new configuration with name
publish_eventswhich allow more details to the frontend JavaScript actions. The default value for this configuration isfalsesince this is used from more advanced users.
Configuration changes:
- PHP Configuration
optimize_sql_queriesis now defaulting tofalse. As currently this is used for relational queries, it is more important to have functionalities like ordering to work as expected and to set it totrueexceptionally when you have big relational data. Also, since we are now providing the new function setRelationDynamic we are able to optimize the queries for relational data anyway, so we can safely assume that this configuration is needed only on exceptional cases.
Functions that has been removed:
- We have removed the functions:
unsetBootstrap,unsetJquery,unsetJqueryUi,unsetReactinstead use theunsetCssTheme,unsetCssIcons,unsetCssThirdParty. Documentation to be updated soon.
API changes:
- The function
setActionButtonMultipleis using the argumenticonNameinstead ofcssClassIcon. - The function
setActionButtonis using the argumenticonNameinstead ofcssClassIcon. - The function
setActionButtonMultiplehas two more parameters$idFieldQueryName = 'id'and$querySeparator = '?'. Documentation to be updated soon. - Field type
checkbox_booleanis removed since it was introducing many bugs. We will revisit this field type in the future. - Field type
timeis removed. Instead, usenative_time. callbackAddFieldfirst parameter has the add field value and not the field type as we had on version 2. More specifically we have:function ($fieldVlue, $fieldName). Documentation to be updated soon.
- New function
setRelationDynamicwhich is getting the data dynamically on search. Very useful for relational tables with big amount of data (e.g. more than 300 rows). The syntax is exactly the same assetRelationfunction. For more check the documentation about setRelationDynamic. - New function
setMasterDetail. For more check the documentation about Master Detail - New function
unsetTools. - New function
defaultColumnWidth. Documentation to be updated soon. - New functions
unsetColumnsButtonandsetColumnsButtonsince we now have a new button "Columns". - Introducing new native field types which are using the browser native input types. New field types are
native_time,native_dateandnative_datetime. Very useful for mobile devices.
We have changed the way that we upload. Now the upload is triggered after the submit form and the UI is the standard native upload input.
Since we are using the new ReactJS library we have changed the way that we load the library. So instead of loading the library with the below code:
// code before
$(document).ready(function () {
$('.gc-container').groceryCrud();
});
We now load the library with the below code instead:
// code now
groceryCrudLoader(document.querySelectorAll(".grocery-crud")[0]);
Also, the settings object is now called by the second parameter of the groceryCrudLoader function instead of the
first one that we've used before.
For example, previously we had:
// code before
$('.gc-container').groceryCrud({
callbackBeforeInsert: function () {
console.log('callback that is called right before the insert');
}
});
And now we should have:
// code now
groceryCrudLoader(document.querySelectorAll(".grocery-crud")[0], {
callbackBeforeInsert: function () {
console.log('callback that is called right before the insert');
}
});
Keep in mind that for security reasons, the publishing of the events by default are now configured to be false.
This means that in order to start using the JavaScript events you need to set the configuration publish_events
to true first.
All the events has changed and there will come from the redux action by replacing / with . starting with gcrud.
For example the redux action type datagrid/data-render will be published as an event gcrud.datagrid.data-render instead.
Also, as now the published events are actual JavaScript events, all the payload will be available through the property
name detail according to the latest Custom Event docs.
All the event names are available through the documentation page of JavaScript events
Keep in mind that since we now have the
publish_eventsconfiguration, we are now suggesting to use the JavaScript events instead of the callbacks. They are easier to implement, and you don't need any extra steps to start using them. For more information about the JavaScript events check the documentation page of JavaScript events
Settings Removals:
settingsobject of JavaScript has removed some values. More specifically:hashEventshas been removed to keep the "one source of truth" configuration. We now have theurlHistorycoming from PHP configurations onlyopenInModalhas been removed to keep the "one source of truth" configuration. We now have theopenInModalcoming from PHP configurations only The below callbacks has been removed:onRowMountis removed since it is only confusing the developement as it is not triggered when the primaryKeyValue is updated. UseonRowUpdateinstead
New settings:
actionButtonsMultiplethat work with the same way asactionButtonsbut it will only show up when we have selected rows. Example:
actionButtonsMultiple: [{
iconName: 'smile',
label: 'Smiley',
onClick: function ({selectedIds}) {
console.log(selectedIds);
}
}],
Settings changes:
The settings object (second parameter of the loader) has slight changes on the callbacks as well.
The callbacks are now getting an object instead of the arguments that we had before.
For example previously we had the below code:
// code before
callbackBeforeUpdate: function (data, primaryKeyValue) {
console.log('callback that is called right before the update',
{data, primaryKeyValue}
);
},
And now we should have:
// code now
callbackBeforeUpdate: ({data, primaryKeyValue}) => { // <-- We now have an object parameter
console.log('callback that is called right before the update',
{data, primaryKeyValue}
);
},