Masterdata

Connect a master data element to your table and get automatically a master data form!


Configure the list columns and the form with JSON to get it functionally and good looking!


The data access rights are easily configured in the backend and displayed in the master data form.



User manual

Masterdata

Listing record functions:

  • List
  • Sort
  • Filter

Crud functions:

  • Create, New record
  • Read, Load record
  • Update, Save record
  • Delete record

Export functions:

  • CSV export
  • Excel export
  • PEF export

Configuration functions:

  • Column order
  • Column width
  • Column selection
  • Data read limit

The form is devided into two parts. In the top is the record list with filter and sorting. In the bottom the record is displayed and can be edited in the form. You can drag the line between to enlarge or shrink the listing.

Listing Functions

Sort

Actually you can sort the displayed records. A callback for the server will be installed later.

Header filter

this are the filters:

  • like (default)
  • =
  • >= or >
  • <= or <
  • !=
Column Order

With drap & drop in the column header you can move the colum to the desired position.

Column Width

Set the cursor between the columns. The Cursor changes to: <->By drag & drop you can adjust the column width.

List

Each record ist displayed in 1 line. The columns are defined in the datadefintion of tabulator. The following symbols display the rights of the user:

  • Edit edit
  • Löschen delete
  • blocked blocked

Functions for the form

New

New empties the form. In future default values for the fields will be supported.

Edit (by Click in the List)

By clicking on the line the recordset is displayed in the form and can be edited. Independent from the displayed columns in tabulator the whole record already loaded in the row. A new load from the server is not necessary.

Cancel

Cancel undos the changes and displays the original record.

Save

Before saving the data a validation by jsonform is done. If its failed you first have to correct the values. In future the data-access-class will do a validation check for the fieldtype and the user rights. Other checks have to be progammed by yourself.

Delete (X click in the List)

The user rights are implemented. If the ban is displayed, deletion is not allowed. After a confirmation question, the record will be deleted. The form displays an empty record.

Dropdown Menu

Options:

  • utf-8 CSV Export
  • Excel Export
  • PDF Export
  • Set read limit
  • Choose columns
  • Save configuration
  • Reset configuration
  • Multi select, set on
Utf-8 CSV Export, Excel Export, PDF Export

You can download the displayed data in the desired format. If not all lines are displayed, please change the record read limit.

Set read limit

You can change the record read limit to an arbitrary value. The read limit is valid until you load a new page.

Choose columns

The Choose colmns dialog allows you to choose the displayed columns.

Save configuration

(only available when loogged in)

With "Save configuration" you save the choosen columns, the order of the columns and the the column width.

Reset configuration

(only available when loogged in)

By reseting the configuration the default columns, its order and with is set to default.

Multi select on

For some special functions the selection of 1 line can be changed to multi line selection.


Developer

Table requirement: primary key of the table

A table for master data has to fullfill the following rules:

  • the Primary key has to consist of a single field
    • INT, autoincrement
  • creatorID (by using the data access rights )
    • INT

The primary key is a hidden field in the master data form. It can not be changed!

Masterdata form on the fly

Checkout the generation of a masterdata form on the fly:

Attention, generate a table is only allowed on this demonstration page. This functionality is normally turned off!

Open data definition as page

you can open the datadefintion as:

Create a data definition out of your table

The data definition contains details for reading, saving and displaying a recordset.

The following steps are necessary to create your own data definition:

  • er_customer, if not exist create it with "k8examples.sql"
  • generate your data definition
  • folder <myproject> create a folder: mycustomer
  • save the data definition in your folder mycustomer with the name "mycustomer" as json file.
  • look in your browser:
    index.php?datadefID=mycustomer&page=masterdata

kitsamples/customerbasic/customerbasic.json:

Place a masterdata plugin element on your page

The masterdata plugin offers this elements:

  • master data form
  • list with optional edit functions
  • form only

To add an edit function to the list, please look for the "edittype" beneath.

Master data

List (tabulator)

Form only

The return values of "masterdata" are:

Datadefinition

Properties and sections:

  • name: the displayed name
  • key: necessary for edit
  • rightcheck: with RBAC, look to the explanation
  • columns: the definition of the table columns
  • masterdata: the main parameters
  • tabulator: the list, please have a look to: tabulator.info
  • k8form: the form, please have a look to: k8form
  • html: the html snippets
  • data: for form only

To change the look of your masterdata form, please configure tabulator (list at the top) and k8form (form at the bottom)

JSON structure:

key

The key column is used for edit functions. If the key value is zero, it's a new record.

rightcheck=1

The backend adds automatically:

settings.masterdata:

  • right_usercreate: "0" or "1"

recordset

  • right_userupdate: "0" or "1"
  • right_userdelete: "0" or "1"

tabulator

This is an part of the customer tabulator definition:

The most often used column properties are:

  • title - Required This is the title that will be displayed in the header for this column
  • field - Required (not required in icon/button columns) this is the key for this column in the data array
  • headerfilter - true for more details look in the tabulator documentation
  • visible - (boolean, default - true) determines if the column is visible
  • hozAlign - sets the horizontal text alignment for this column (left|center|right)
  • headerHozAlign - sets the horizontal text alignment for this columns header title (left|center|right)
  • width - sets the width of this column, this can be set in pixels or as a percentage of total table width (if not set the system will determine the best)
  • formatter - Tabulator offers a wide range of formatters for strings, numbers, dates, ...
  • formatterParams - additional parameters you can pass to the formatter

For more details look to:

Columns can easily removed or added. if desired you change the order of the columns. If you extend the sql-statement, you can easily add the columns here.

k8form

This is an part of the customer k8form definition:

The most often used column properties are:

  • tagName - default: input This is the tag of the form element. Other supported tags are:
    • select
    • textarea
    • button
  • type - for input, button most of the HTML5 input types are supported
  • name - Required This is the name of the database column
  • label - the label of the form element
  • decimals - the decimals by type=number
  • attributes{} - additional attributes for the field
    • maxlength - the maximum allowed charaters of the field
  • required - defines if an form element is required
  • disabled - defines if an form element is disabled
  • inputgroup - declares an inputgroup, a bootstrap 5 element, consist multiple elements
  • options - for select defines the options of a select element

For more details look to:

Thanks to the container property of k8form HTML layout can be managed and fieldsets or multiple block can be displayed.

k8form, 2 blocks

masterdata/templates/datadefinition_k8form_2blocks.json:

Bootstrap needs 3 containers to create 2 blocks:

  • class: row
    • class: col-sm-6
    • class: col-sm-6

k8form, datalist (example: employee)

datalist example for employee "address":

"Address", name: "gender"

This field allows any entry to address the contact person. The "list" attribute points to a "datalist". In the data list you will find suggestions for field input.

"datalist", id: "gender_datalist"

Here are the suggestions for the field input listed. This "tag" is not displayed in the form. It has no label.

So the "fieldwraptemplate" only consist out of the "fieldelement". It also has no "class" -> the fieldclass is set to empty.

The "id" is same to gender attribute "list".

The "tagName" is "datalist".

In the "innerHTML" the options (list entries) are defined as HTML elements.

k8form, with select

example for a status field:

tagName

To select values out of an option list, you have have to declace a HTML tag: "select".

options

The options list allows you to define value pairs (value, text) to select from. If the text should be saved in field and table, you don't need a value.

tabulator, with select

example for a status field:

headerFilter: list

This defines a select field in the header filter.

headerFilterParams

The headeFilterParams define the values, which can be selected.

formatter:#function#k8tabulatorformatter

The k8tabulatorformatter allows to define values, which are displayed with the "text".

formatterParams

The value list contains the "text" property, which is displayed.

masterdata

defaultvalues

The defaultvalues allows to set default values for a new record in the form.

clause

The clause allows to filter the data.

url_...

  • Ajax
    • load
    • read_filter
    • save
    • del
  • Dialog
    • new
    • edit
    • master
    • detail

edittype

  • 0 no controls
  • 1 insert with reload (only catalog plugin)
  • 2 innerHTML (form_selector)
  • 3 overlay
  • 4 new tab
  • 5 new window
  • 6 own line in catalog template (only catalog plugin)
  • 7 own line with special template (only catalog plugin)
  • 8 master data form
  • 9 link in this window

SQL statement

sql_derived example:

Please write the sql_statement or sql_derived in the datadefinition in one line (JSON compliant)!
The "sql_derived" property is important by using the view with tabulator, otherwise the property "sql_statement" should be used because it's a little bit faster.

The placeholder are:

  • §select: additional fields are inserted:
    • rightuser_update
    • rightuser_delete
  • '' as k8select: same §select
  • §dateformat: the SQL date string is inserted
  • WHERE 1=1: Where condition, here the "WHERE ".$clause is inserted
  • §userID: $_SESSION['userID']
  • §domain_language: $GLOBALS['domain_language']

Alternatively the include "getEntries_sql" can be used to write the statement direct in php.

Call back functions

Extend the datadefintitions with call back functions:

the parameters:

  • settings: configuration of the element
  • el_md: the masterdata html element
  • dat: the record with column value pairs
  • e: the event
  • el: the source element
  • selected: the selected rows
  • row_actual: the current row

add tinymce

masterdata/templates/tinymceset.js

Create your datadefintion JavaScript file. Copy the line from the template into your file and add your datadefID to the settings variable.

additional declarations in the datadefinition:

In the head of the page you have to add:

  • the tinymce library: tinymce/tinymce.js
  • the tinymce template: masterdata/templates/tinymce.js

After the declaration of the JavaScript variables at head_end the call back functions are added to the datadefinition: settings. The JavaScript file for this is masterdata/templates/tinymce.js.

In "k8form" the textareas with the class tinymce will get the tinymce editor.

The image list for tinymce is initialized by the init of tinymce. By each record the image_list changes, so tinymce is removed and initialized again.

The tinymce template consist the call back functions for your form. If you need to extend the call back functions or change the configuration, just copy the template in your datadefinition folder and change the link in your datadefinition.

More information about tinymce are in: TinyMCE docs

add image support

additional declarations in the datadefinition:

The upload has to be enabled (true). The settings specify the details of the files to be uploaded.

Frontend

the following elements are added into the masterdata plugin:

  • Upload area for the image
  • Image list with with sorter and control elements

If tinymce is enabled the image list is also displayed and updated in tinymce.

showtext

"true" displays the filename.

minImageWidth, minImageHeight

The min values ​​ensure that a minimum resolution is guaranteed.

resizeMethod

  • contain:
    • the image dimensions are scaled down to the specified values.
    • the aspect ratio of the uploaded image is retained
  • crop:
    • the image dimensions are croped to the resizedWidth and resizeHeight
    • the aspect ratio corresponds to the resizedWidth and resizeHeight

Backend

by reading the main recordset, the following columns are added:

  • image_ID
  • image_file
  • image_orientation
  • image_aspectratio
  • image_width
  • image_height
  • image_count
  • image_array
    • array with images, same the columns above

Menu

menuleftobj, for more details go to dropdown.

displaymodes (true by default):

  • inlist (displayed in master data form or list)
  • inform (displayed only in form)
  • atlist (displayed only in a different form by a link)

Call back function, cbMenuleft:

html

The html snippets define the looking of the master data form. To overwrite the default, you can define your own snippets.

settings.html.masterdata.<property>

  • layout
  • wrapper
  • headline
  • filterformwrapper
  • tabulatorwrapper
  • formwrapper
  • main
  • footline

Create a folder for the datadefnition, name: <datadefID>. Write the HTML-Files with this names:

<datadefID>_<masterdata>_<property>.html

Please regard in your snippets the classes:

  • "masterdata"
  • "tabulator"
  • "js"
  • "js_dirty" for the edit symbol
  • "js_middle" for the message by messages mode<>4
  • Save button needs to be: type="submit"
  • Cancel button: class="js_cancel"

if you place tabulator and form side by side:

An example for a side by side form is in "kitsamples/customerleft".

data

data is only supported in form mode (notabulator:true):

Linking <select> by page init

Requirements for the data definition:

  • optionsadditional[]
    • datadefID the source datadefinition need to be declared
    • column_mapping
    • fieldname
    • tabulatorcolumn
    • emptytext
    • defaultclause
  • masterdata, sql_statement
    • the column "category" with the title can be joined for catalog output

datadefID:

  • The datadefID of the source datadefinition needs to be entered here.

column_mapping:

This example uses an existing data definition as recordsource. But the option tag has this structure, which needs to be served:

  1. <option>"text"</option>
  2. <option value="value">"text"</option>
  3. <option data-value="additional attribute" value="value">"text"</option>

The columns of the data source:

  • groupID
  • title
  • value

With the column mapping the options are filled easily, column_mappping:

  1. {"text":"title"}
  2. {"value":"groupID","text":"title"}
  3. {"data-value":"value","value":"groupID","text":"title"}

emptytext:

  • none (default)
  • standard (please select)
  • your text

An empty text is only shown in mode 1. In mode 0 you get an empty option instead.

defaultclause:

The "defaultclause" allows to filter the data.

Example for the item category:

tabulator categoryID

this parameters need to be set:

  • headerFilter:"list", allow to choose from the value list
  • formatter:"#function#k8tabulatorformatter#", this formatter displays the text in the rows instead of the values
  • formatterParams":{"type":"color"}, defines the type of the formatter

The value lists are added automatically by processing "optionsadditional".

k8form categoryID

The "tagname" is set to "select". This HTML element allows to select from an option list. The option list is filled automatically by processing "optionsadditional".

Linking with datalist

To link our current form with another data definition we need both data definitions:

  • input data definition: our current definition "mycustomer"
  • source data definition: where we read the records from: "k8searchuser"

The source data definition will be the definition with the logged in users:

  • k8searchusers

The input data definition is linked to the Primary key of the source data defintion. So we need an ID field in the input data definition:

  • reprenstativeID

To search for the user the name will be typed in. So we need a second field for the name:

  • representativename

The representativename needs to be read by loading the record into our input data definition. Therefore are adoptions necessary in:

  • the sql statement
  • the tabulator columns

Requirements for the input data definition:

  • settingsadditionals[]
    • the source data definition need to be declared
  • k8form, fields
    • datalist{}
      • look for the additional parameters

k8form attributes

list:

The "list" is defined like this:

  • <field name>_datalist

autocomplete:

Only the results from the datalist should be shown here. Other suggestions for the content are shut off.

k8form datalist

datadefID:

The datadefID of the source data definition needs to be entered here. It has also to be declared in "settingsadditional".

IDfield:

The IDfield is the field which contains the primary key of the source table.

onlyoptions:

  • true: only options from the list are allowed
  • false: all entries are allowed

If another source table is linked the value must be true. After choosing the value the primary key of the source table is inserted into the "IDfield".

Example for linking the user from the table "k8login":

The sql statement better displayed with line breaks:

Example for data-fieldlist:

  • "data-fieldlist":"accountID,accountname=customername,email,phone"

Form elements can be filled with values from the source record.

Requirements for the source datadefintion:

In the source table the column <name> should be a "unique" column. This column is requested in the form.

Linking <select> with Ajax

Attention, not working well when the value is set before Ajax filled the options

Requirements for the data definition:

  • settingsadditional[]
    • the source datadefinition need to be declared
  • masterdata, sql_statement
    • the column "representative" with the username need to be joined
  • k8form, fields
    • dataoptions{}
      • look for the additional parameters

datadefID:

The datadefID of the source datadefinition needs to be entered here. It has also to be declared in "settingsadditional".

mode:

  • 0: <option>"datalistcolumn"</option>
  • 1: <option value="key">"datalistcolumn"</option>

emptytext:

  • none (default)
  • standard (please select)
  • <your text>

An empty text is only shown in mode 1. In mode 0 you get an empty option instead.

defaultclause:

The "defaultclause" allows to filter the data.

Example for the item category:

Requirements for the source datadefintion:

In the source table the column <name> should be a "unique" column. This column is requested in the form.