4 tips about the usage of widgets within Mendix
Blog written by Johan Munneke, Mendix Expert & Mendix MVP at Aiden
You will probably recognize it: the customer has a problem and you have a nice solution in mind, but you still have no idea how you are going to implement it. It should look good, work well and it should be easy to use.
There are often several ways to solve an issue, each with its own advantages and disadvantages. In this blog I will give four tips about the use of widgets within Mendix to make you aware in which situation you can consider using a widget.
Tip 1: A lot can be solved using standard Mendix components, however, do not be afraid to use widgets when needed
Most requirements can be solved using standard Mendix components, perhaps with a bit of styling. However, this will not always suffice. In some cases you can build something, but you need quite some workarounds and you doubt whether this is the correct approach. At these moments you can check whether you can better use something else, for example a pluggable widget. A lot of times widgets are not used for different reasons; widgets might be harder to maintain or to develop and you might be dependent on updates done by someone else.
However, if you need a lot of workarounds using standard components, this can also be quite some work to develop and in some cases even harder to maintain or to understand. Also, you might have to tweak the requirements to what is possible. You must ask yourself the question whether this will be the correct choice or that you can better spend some effort in developing something that might look a bit harder, but that you only have to setup once and can be reused for similar requirements.
Some time ago my team was asked to build a planning application. The most important requirements were to show the planning of the users and it should be easy to make changes to the planning. If you want to build this with standard Mendix components, you will probably use a couple of nested list views to show the planning. However, it would almost be impossible to build a complete planning application that performs well and can handle tons of data, let alone including functionalities such as drag & drop, resizing of activities and being able to show them accurately to the minute. When we wrote down all requirements for the application, it was quite clear that standard components would not suffice and that we would need a custom widget.
Tip 2: Do not try to reinvent the wheel
As of Mendix 8 widgets are based on React. This offers a lot of new possibilities. One of the biggest advantages is that a lot of external libraries are available within React. These libraries can easily be used within your own widgets. You can use what is already available and do not have to ‘reinvent the wheel’. Especially for bigger components, like the planning widget discussed earlier, this offers quite some benefits. If you must write all code yourself, you will need weeks for such a big component.
By reusing a library, you only need a couple of lines of code to use the basis of the component and use data stored within Mendix. You only need to take care of the communication between the widget and Mendix and to make sure that the widget is easy to use for other developers, but a lot of logic is handled by the library. Even if the library does not have all features you need, you can add your own logic.
Tip 3: Do not think too big, small components can also increase the user experience
Not all widgets need to be big. There are also a lot of small widgets that can increase the user experience, for example a datetime picker, loading skeleton, toast messages or an autocomplete widget. These are all examples of components that can enhance the user experience and user interface, without you spending days or weeks of work in the development of custom components.
Tip 4: Widgets can be reused for similar requirements
When somebody asks something that seems impossible by default, people will mostly try to find some workarounds to make it work. This makes sense, because we all know the standard components and we know they have been tested carefully. However, this should not be at the expense of the user experience. In a lot of cases you or your colleagues will encounter similar issues in different projects. In this case it can certainly be worth investing a few days to create a pluggable widget and thus increase the ease of use within various applications and help your fellow developers and yourself in the future. In addition, there are a lot of components available within React which have also been tested extensively.
Not everyone needs to develop pluggable widgets, because this also requires specific knowledge and it is also needed in limited scenarios. Though, it is good to know when to consider using one. If you have great ideas and you do not want to or cannot develop pluggable widgets, there may be a colleague who can help you out! If you are interested in developing widgets yourself, there are plenty of resources to help you get started, for example learning paths, how-to’s, online trainings, Mendix forum and documentation. Please visit the following links to learn more:
If you want to know more about the widgets that I developed so far, you can always contact me! Later this year we will organize an event about widget development. Follow Aiden and my account to stay up to date about this and any future events.