From 0dcf1980cabb6cd85746d20296f9202a543b5f64 Mon Sep 17 00:00:00 2001 From: Cris Date: Tue, 22 Oct 2019 16:27:27 +0200 Subject: [PATCH] Optimized HEADER FILTER in tabulator to use COMPARISON OPERATORS Now header filter parses the given filterstring. If it starts with a comparison operator it will be used for comparison. Otherwise just compare the stringnumbers to be equal. --- .../lehre/lehrauftrag/acceptLehrauftrag.php | 27 +++++++++++++------ .../lehrauftrag/acceptLehrauftragData.php | 7 +++-- .../lehre/lehrauftrag/approveLehrauftrag.php | 27 +++++++++++++------ .../lehrauftrag/approveLehrauftragData.php | 7 +++-- .../lehre/lehrauftrag/orderLehrauftrag.php | 27 +++++++++++++------ .../lehrauftrag/orderLehrauftragData.php | 4 +-- 6 files changed, 69 insertions(+), 30 deletions(-) diff --git a/application/views/lehre/lehrauftrag/acceptLehrauftrag.php b/application/views/lehre/lehrauftrag/acceptLehrauftrag.php index 0f8fab42e..e03703ed2 100644 --- a/application/views/lehre/lehrauftrag/acceptLehrauftrag.php +++ b/application/views/lehre/lehrauftrag/acceptLehrauftrag.php @@ -127,15 +127,26 @@ $this->load->view( // Header filter // ----------------------------------------------------------------------------------------------------------------- - // Casts string formatted float values to float when using the filter. - // This will allow correct filtering. - function hf_compareWithFloat(headerValue, rowValue, rowData, filterParams){ - //headerValue - the value of the header filter element - //rowValue - the value of the column in this row - //rowData - the data for the row being filtered - //filterParams - params object passed to the headerFilterFuncParams property + // Filters values using comparison operator or just by string comparison + function hf_filterStringnumberWithOperator(headerValue, rowValue, rowData){ - return parseFloat(headerValue) <= parseFloat(rowValue); //must return a boolean, true if it passes the filter. + // If string starts with <, <=, >, >=, !=, ==, compare values with that operator + var operator = ''; + if (headerValue.match(/([<=>!]{1,2})/g)) { + var operator_arr = headerValue.match(/([<=>!]{1,2})/g); + operator = operator_arr[0]; + + headerValue = headerValue + .replace(operator, '') + .trim() + ; + + // return if value comparison is true + return eval(rowValue + operator + headerValue); + } + + // If just a stringnumber, return if exact match found + return parseFloat(rowValue) == headerValue; } // ----------------------------------------------------------------------------------------------------------------- diff --git a/application/views/lehre/lehrauftrag/acceptLehrauftragData.php b/application/views/lehre/lehrauftrag/acceptLehrauftragData.php index 4a6b9aa5b..d10d2781a 100644 --- a/application/views/lehre/lehrauftrag/acceptLehrauftragData.php +++ b/application/views/lehre/lehrauftrag/acceptLehrauftragData.php @@ -358,8 +358,11 @@ $filterWidgetArray = array( semester: {headerFilter:"input"}, lv_oe_kurzbz: {headerFilter:"input", width: "12%"}, gruppe: {headerFilter:"input", width: "5%"}, - stunden: {align:"right", headerFilter:"input", bottomCalc:"sum", bottomCalcParams:{precision:1}, width: "5%"}, - betrag: {align:"right", headerFilter:"input", headerFilterPlaceholder:">=", headerFilterFunc: hf_compareWithFloat, + stunden: {align:"right", + headerFilter:"input", headerFilterFunc: hf_filterStringnumberWithOperator, + bottomCalc:"sum", bottomCalcParams:{precision:1}, width: "5%"}, + betrag: {align:"right", + headerFilter:"input", headerFilterFunc: hf_filterStringnumberWithOperator, bottomCalc:"sum", bottomCalcParams:{precision:2}, bottomCalcFormatter:"money", bottomCalcFormatterParams:{decimal: ",", thousand: ".", symbol:"€"}, width: "8%"}, vertrag_id: {visible: false}, diff --git a/application/views/lehre/lehrauftrag/approveLehrauftrag.php b/application/views/lehre/lehrauftrag/approveLehrauftrag.php index e7c0383b9..d2eb3de13 100644 --- a/application/views/lehre/lehrauftrag/approveLehrauftrag.php +++ b/application/views/lehre/lehrauftrag/approveLehrauftrag.php @@ -146,15 +146,26 @@ $this->load->view( // Header filter // ----------------------------------------------------------------------------------------------------------------- - // Casts string formatted float values to float when using the filter. - // This will allow correct filtering. - function hf_compareWithFloat(headerValue, rowValue, rowData, filterParams){ - //headerValue - the value of the header filter element - //rowValue - the value of the column in this row - //rowData - the data for the row being filtered - //filterParams - params object passed to the headerFilterFuncParams property + // Filters values using comparison operator or just by string comparison + function hf_filterStringnumberWithOperator(headerValue, rowValue, rowData){ - return parseFloat(headerValue) <= parseFloat(rowValue); //must return a boolean, true if it passes the filter. + // If string starts with <, <=, >, >=, !=, ==, compare values with that operator + var operator = ''; + if (headerValue.match(/([<=>!]{1,2})/g)) { + var operator_arr = headerValue.match(/([<=>!]{1,2})/g); + operator = operator_arr[0]; + + headerValue = headerValue + .replace(operator, '') + .trim() + ; + + // return if value comparison is true + return eval(rowValue + operator + headerValue); + } + + // If just a stringnumber, return if exact match found + return parseFloat(rowValue) == headerValue; } // ----------------------------------------------------------------------------------------------------------------- diff --git a/application/views/lehre/lehrauftrag/approveLehrauftragData.php b/application/views/lehre/lehrauftrag/approveLehrauftragData.php index 277da450d..96aa7d3fe 100644 --- a/application/views/lehre/lehrauftrag/approveLehrauftragData.php +++ b/application/views/lehre/lehrauftrag/approveLehrauftragData.php @@ -377,8 +377,11 @@ $filterWidgetArray = array( lv_oe_kurzbz: {headerFilter:"input"}, gruppe: {headerFilter:"input"}, lektor: {headerFilter:"input"}, - stunden: {align:"right", headerFilter:"input", bottomCalc:"sum", bottomCalcParams:{precision:1}}, - betrag: {align:"right", headerFilter:"input", headerFilterPlaceholder:">=", headerFilterFunc: hf_compareWithFloat, + stunden: {align:"right", + headerFilter:"input", headerFilterFunc: hf_filterStringnumberWithOperator, + bottomCalc:"sum", bottomCalcParams:{precision:1}}, + betrag: {align:"right", + headerFilter:"input", headerFilterFunc: hf_filterStringnumberWithOperator, bottomCalc:"sum", bottomCalcParams:{precision:2}, bottomCalcFormatter:"money", bottomCalcFormatterParams:{decimal: ",", thousand: ".", symbol:"€"}}, vertrag_id: {visible: false}, vertrag_betrag: {visible: false}, diff --git a/application/views/lehre/lehrauftrag/orderLehrauftrag.php b/application/views/lehre/lehrauftrag/orderLehrauftrag.php index 92b5003f3..cc7eb8bf0 100644 --- a/application/views/lehre/lehrauftrag/orderLehrauftrag.php +++ b/application/views/lehre/lehrauftrag/orderLehrauftrag.php @@ -144,15 +144,26 @@ $this->load->view( // Header filter // ----------------------------------------------------------------------------------------------------------------- - // Casts string formatted float values to float when using the filter. - // This will allow correct filtering. - function hf_compareWithFloat(headerValue, rowValue, rowData, filterParams){ - //headerValue - the value of the header filter element - //rowValue - the value of the column in this row - //rowData - the data for the row being filtered - //filterParams - params object passed to the headerFilterFuncParams property + // Filters values using comparison operator or just by string comparison + function hf_filterStringnumberWithOperator(headerValue, rowValue, rowData){ - return parseFloat(headerValue) <= parseFloat(rowValue); //must return a boolean, true if it passes the filter. + // If string starts with <, <=, >, >=, !=, ==, compare values with that operator + var operator = ''; + if (headerValue.match(/([<=>!]{1,2})/g)) { + var operator_arr = headerValue.match(/([<=>!]{1,2})/g); + operator = operator_arr[0]; + + headerValue = headerValue + .replace(operator, '') + .trim() + ; + + // return if value comparison is true + return eval(rowValue + operator + headerValue); + } + + // If just a stringnumber, return if exact match found + return parseFloat(rowValue) == headerValue; } // ----------------------------------------------------------------------------------------------------------------- diff --git a/application/views/lehre/lehrauftrag/orderLehrauftragData.php b/application/views/lehre/lehrauftrag/orderLehrauftragData.php index 9379b77be..05cacb1f9 100644 --- a/application/views/lehre/lehrauftrag/orderLehrauftragData.php +++ b/application/views/lehre/lehrauftrag/orderLehrauftragData.php @@ -388,11 +388,11 @@ $filterWidgetArray = array( gruppe: {headerFilter:"input"}, lektor: {headerFilter:"input"}, stunden: {align:"right", - headerFilter:"input", headerFilterPlaceholder:">=", headerFilterFunc: hf_compareWithFloat, + headerFilter:"input", headerFilterFunc: hf_filterStringnumberWithOperator, bottomCalc:"sum", bottomCalcParams:{precision:1}}, stundensatz: {visible: false}, betrag: {align:"right", - headerFilter:"input", headerFilterPlaceholder:">=", headerFilterFunc: hf_compareWithFloat, + headerFilter:"input", headerFilterFunc: hf_filterStringnumberWithOperator, bottomCalc:"sum", bottomCalcParams:{precision:2}, bottomCalcFormatter:"money", bottomCalcFormatterParams:{decimal: ",", thousand: ".", symbol:"€"}}, vertrag_id: {visible: false},