Nodejs Express server
Create table
The data is to be presented in the form of a list, and the table is to provide the following functions:
- filter
- sort
- form column
The table is realized (implemented, shown) knockout with the View Model ModelView pattern
βββ πclt
βΒ Β βββ πcss
βΒ Β βΒ Β βββ π app.css
βΒ Β βββ πjs
βΒ Β βββ applyBindings.js
βΒ Β βββ πdist
βΒ Β βΒ Β βββ π aktionen.class.js View Model
βΒ Β βΒ Β βββ π createTable.class.js
βΒ Β βββ πjson
βΒ Β βββ π agenten.json
βΒ Β βββ π agentenstatus.json
βΒ Β βββ π aktionen.json
βΒ Β βββ π aktionsagenten.json
βΒ Β βββ π produkte.json
βββ π header.php
βββ π pgreq.php
βββ π README.md
βββ π req.php
The data must look like the following when you fetch the data from Databank
BEGIN
declare v_result longtext default '';
declare v_agenten longtext;
set v_agenten = (
SELECT
CONCAT('['
, group_concat(
JSON_OBJECT(
'agentenID', JSON_OBJECT('value', agentenID, 'key', concat('spf_TableFormFuerAland(',agenten.agentenID, ')')),
'name', JSON_OBJECT('value', name, 'key', concat('spf_TableFormFuerAland(',agenten.agentenID, ')')),
'vorname', JSON_OBJECT('value', vorname, 'key', 'false'),
'aktionen', JSON_OBJECT('value', spf_AgentAnzahlAktion(agentenID, 1) collate latin1_general_ci, 'key', concat('getAktionen(',agentenID, ')')),
'agentenstatusID', JSON_OBJECT('value', agentenstatusID, 'key', 'false'),
'anmelden', JSON_OBJECT('value', anmelden, 'key', 'false'),
'mitschneiden', JSON_OBJECT('value', mitschneiden, 'key', 'false'),
'bewerten', JSON_OBJECT('value', bewerten, 'key', 'false'),
'alias', JSON_OBJECT('value', alias, 'key', 'false'),
'arbeitgeberID', JSON_OBJECT('value', arbeitgeberID, 'key', 'false'),
'letzterzugriff', JSON_OBJECT('value', letzterzugriff, 'key', 'false'),
'agentenpositionsID', JSON_OBJECT('value', agenten.agentenpositionsID, 'key', concat('getPosition(', agentenID, ')')),
'agentenposition', agentenposition.bezeichnung,
'bilddatenID', JSON_OBJECT('value', bilddatenID, 'key', 'false'),
'einloggen', JSON_OBJECT('value', einloggen, 'key', 'false'),
'mitschnittmodusID', JSON_OBJECT('value', mitschnittmodusID, 'key', 'false')
)
)
, ']')
FROM agenten
inner join agentenposition on agentenposition.agentenpositionsID = agenten.agentenpositionsID
where agenten.agentenstatusID <> 6
);
set v_result = (select json_object(
'table', JSON_extract(v_agenten, '$') //! You must decide whether you have a table or tableSub or tableForm
));
return v_result;
ENDOr that Json data should look like this :
{
"Table": [
{
"agentenID": {
"value": 3,
"key": "agentenID"
},
"name": {
"value": "Training",
"key": "agentenID"
},
"vorname": {
"value": "1",
"key": "agentenID"
},
"agentenstatusID": {
"value": 1,
"key": "agentenID"
},
"anmelden": {
"value": 1,
"key": "agentenID"
},
"mitschneiden": {
"value": 0,
"key": "agentenID"
},
"bewerten": {
"value": 0,
"key": "agentenID"
},
"alias": {
"value": "",
"key": "agentenID"
},
"arbeitgeberID": {
"value": 0,
"key": "agentenID"
},
"letzterzugriff": {
"value": "2019-10-22 17:24:09",
"key": "agentenID"
},
"agentenpositionsID": {
"value": 30,
"key": "agentenID"
},
"agentenposition": "Agent",
"bilddatenID": {
"value": null,
"key": "agentenID"
},
"einloggen": {
"value": 0,
"key": "agentenID"
},
"mitschnittmodusID": {
"value": 1,
"key": "agentenID"
}
}
]
}class aktionenVM realisiert das ViewModel
self.nodes: An observableArray that is used to store the data.self.columns: contains the column headers to be displayed (composed of title, sorting, input filte for search).self.rows: enthΓΆlt die anzuzeigenen Splaten-body (bestet aus data) and Used to limit the amount of times the rows are updatedself.isLoading: A boolean value that is used to show or hide the loading animation.self.selectedPropertys: An observableArray that is used to store the selected properties.
self.getProperty: return unique list (one object) of propertiesself.getAgenten: returns unique list (one object) of agenten propertiesself.getAgentenStatus: returns unique list (one object) of AgentenStatus Propertiesself.getAktionen: returns unique list (one object) of Aktionen Propertiesself.getAktionenagenten: returns unique list (one object) of Aktionenagenten Propertiesself.getProdukte: returns unique list (one object) of Produkte Propertiesself.selectedAllPropertys: A computed observable that is called when the selectedPropertys changes. it setting all selectedAllPropertys of Trueinit: A function that is called when the data is loaded.self.createTable: Creating a new instance of the createTable class. und werde Rows, Columns, updateRows, rowsLength, isLoading ΓΌbergebenself.updateRows: A function that is called when the rows are updated.self.getJson: A function that is used to load the json files.
view fΓΌr die dagestellte tabelle und werde die daten bearbeitet, sortiert, gefiltet.
self.updateRows: Used to update the rows in the table. why dont used observable besause it's a callback Function // TODOself.isLoading: A boolean value that is used to show or hide the loading animation.self.paramColumns: Creating a new array with the Columns and Backup Data.self.paramData: Creating a new array with the Rows and Backup Data.self.updateParamData: Used to update the rows in the table.self.paramFieldKey: Setting the fieldKey to the params.fieldKey or to the string 'field'. // TODOself.paramDisplayNameKey: Setting the displayNameKey to the params.displayNameKey or to the string 'displayName'. //TODOself.paramSort: Used to sort the data by starting an applicationself.searchTxt: Search for a specific value in a nested object and return the key path An observable that is used to store the search text.self.searchLst: An observable array that is used to store the search text.self.searchTxtLst: Used to store the search text.
self.search: A function that is used to search in a nested object.self.filterNode: A function that is used to search in a nested object.self.searchInSubNode: Search in a subnode Searching in a nested object.self.searchInNode: Search in a subnode Searching in a nested object.self.koColumnHeaders: Creating a new array with the columns and the searchInput.self.koRows: Creating a new array with the Rowsself.fold: A funktion used to sort the data and Checking if the value is the same as the paramSortself.sortA_Z: A function used to sort the data by a-z.self.sortZ_A: A function used to sort the data by z-a.self.sort: A funktuion used to sorting the data.self.removeItemByKey: Removing an item from an array by key.
This function can lead to errors: you need to edit this function to get the data from server. if you use the function.
connectToServer = async (url, type, async, body) => {
return new Promise((resolve, reject) => {
$.ajax({
url: url, // localhost
type: type, // get | post
async: async, // true | false
data: body, // null | sessionID
success: async (data) => {
//-------------------------------------------------------
//! This is a temporary fix for the data that is being returned from the server.
//TODO: Remove this fix when the server is fixed.
//TODO: Or make a function that checks if the data is correct.
//TODO: Or you need to customize here with your data
//-------------------------------------------------------
if (data == null || typeof data == 'string' || data.length <= 0) {
reject('error: ' + data);
}
var isTableOrEd = Object.keys(data.msg[0]);
data = data.msg[0][isTableOrEd];
data = JSON.parse(data);
isTableOrEd = Object.keys(data);
data = data[isTableOrEd];
resolve(data);
},
error: function (error) {
reject(error);
},
});
});
};










