Budibase Data Binding
After migrating from a spreadsheet into a PostgreSQL database, I could get to work building an interface for my data with Budibase. The big sales pitch for Budibase is that I could be up and running in minutes. And that is indeed true as long as the interface I want is a big spreadsheet-like table. If I want something more specifically tailored to my data, it's going to take more than a few minutes. Laying out a page with data input/output elements is a pretty straightforward drag-and-drop WYSIWYG affair, but bringing that page to life with real data requires Budibase data binding.
Immediately following introduction of data binding, Budibase documentation jumps into discussing the two supported languages. ("Handlebars" and "JavaScript".) I felt they should have covered data binding scope first. In hindsight understand that would have been a useful mental boundary before diving into syntax details of the two methods.
Handlebars
The syntax more commonly seen in Budibase documentation is referred to as "handlebars", and it can be recognized by the two curly braces that open and close a handlebar expression. Judging by a package.json
file, this was built on top the HandlebarsJS library alongside a Budibase helper library. My first exposure to it in Budibase documentation was this example from the Design/Components/Table page:
KG
This extracts data from the "KGS" column of all selected rows in Table Block 1, add those values together, round the sum to two decimal places, then append a "KG" suffix for display. Handlebars syntax allowed specifying such common operations quickly, a really powerful tool but completely inscrutable to a beginner not versed in the compact syntax. It also has its limitations. A significant one is that output of every handlebar expression is always a string. (Called out at the end of the formula page.) Plus, its extensive helper library can't cover everything. There would inevitably come a time when we need access to a general-purpose language for the job.
JavaScript
If I want to create a binding that can't be done in handlebars (either fundamental limitation or just I don't know how) I can click a button to switch to JavaScript mode. This opens up a small text window for a JavaScript code snippet editor and my first step from "no-code" Budibase to "low-code" Budibase. Input comes from an expression that starts with a jQuery-like "$". The counterpart to the handlebars example above would be something like $('Table Block 1.Selected Rows')
. That expression returns a JavaScript array (one element is one row) of dictionaries (key/value pairs of column name and value). From there, standard JavaScript syntax and libraries apply, and my JavaScript code runs until a return
statement at the end with a processed value for Budibase to use.
Since the pattern is to consume an array and produce a single output, many of the JavaScript data binding examples use reduce()
. That seems to be the most popular one, though other JavaScript array iterators are applicable. I think it's because handlebars can do most of the rest. In contrast, reduce()
takes a snippet of custom logic and applies it. Generally speaking there are times not to use reduce()
but as far as I can tell a Budibase binding function is unlikely to touch upon those scenarios.
To venture beyond Budibase default data presentation of a big spreadsheet-like table, I needed a bare minimum working knowledge of data binding in order to build my own interfaces. It didn't take long before I encountered problems, as expected for a beginner diving in for the first time.