Tables¶
Very basic table¶
A table in Kontrl is a bunch of data that belongs together. Think of a table in SQL, a collection in MongoDB or REST or any other data source which has data that belongs together in some way or another.
A table only has a few mandatory settings.
const kontrl = require("kontl");
kontrl.table({
// How would you like to identify this table?
name: "",
// The fields of this table that are used to uniquely identify the data.
identifier: ["id"],
// Which fields does this table have?
fields: [
"first_name",
"last_name",
"email"
],
// The resolver, telling kontrl where it should get the data for this table.
// See "resolvers" section for more information.
resolver: kontrl.resolver.postgres(pgclient, "users")
});
This is the simplest representation of a table. There are many more optional settings.
If you define your table in this way, kontrl will work and give you basic CRUD functionality.
Table groups¶
Once you have more than one or two tables it can be a real benefit to group your tables together.
kontrl.table({
// Other settings
name: "posts",
group: "Blog"
});
kontrl.table({
// Other settings
name: "comments",
group: "Blog"
});
When two or more tables are in the same group, they will be shown in the dashboard as being in the same group.
Hiding a table¶
Sometimes a table has to exist but you don’t want to show this table to the user. Say for example the join table in a many to many relation.
In that case it’s possible to hide a table in the table settings.
kontrl.table({
// Other settings
settings:{
hidden: true
}
})