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 datadefinition as page

you can open the datadefintion as:

Create a datadefinition out of your table

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

The following steps are necessary to create your own datadefinition:

  • er_customer, if not exist create it with "k8examples.sql"
  • generate your datadefinition
  • folder <myproject> create a folder: mycustomer
  • save the datadefinition 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

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:

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.

resizeMethod

  • contain: the aspect ratio is fix
  • crop: the image is croped 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.

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> 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.

Linking <select> by page init

Requirements for the data definition:

  • optionsadditional[]
    • datadefID the source datadefinition need to be declared
    • column_mapping
    • fieldname
    • emptytext
    • defaultclause
  • masterdata, sql_statement
    • the column "representative" with the username need to be joined

datadefID:

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

column_mapping:

This example uses an existing datadefinition 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:

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 with datalist

Requirements for the input data definition:

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

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.

datalist

datadefID:

The datadefID of the source datadefinition 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":

Requirements for the source datadefintion:

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