Skip to content
Snippets Groups Projects
Commit b0db6bae authored by Carlos Vega's avatar Carlos Vega
Browse files

matched part it's now highlighted to facilitate reading.

parent e046489e
No related branches found
No related tags found
1 merge request!169Enhancement/subject table changes
Pipeline #6603 passed
...@@ -101,6 +101,29 @@ function createColumn(dataType, name, filter, visible, sortable, renderFunction) ...@@ -101,6 +101,29 @@ function createColumn(dataType, name, filter, visible, sortable, renderFunction)
}; };
} }
/*
We use an auxiliary function to create the function due to the lack of block scope in JS.
https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
*/
function createRenderFunction(columnRow){
return function(data, type, row, meta){
/*
Fancy highlighting for the column matches.
*/
if(columnRow.filter == 'string_filter'){
//obtain the input element by its placeholdername which matches the column name: e.g.: <input type="text" style="width:80px" placeholder="First name">
filter_value = $(`input[placeholder="${columnRow.name}"]`).val();
//if there is any filter, we highlight the matching part
if(filter_value != undefined && filter_value.length > 0){
//global and case insensitive replacement
return data.replace(RegExp(filter_value, 'gi'), `<span class="highlight_match">${filter_value}</span>`);
}
}
return data;
};
}
function getColumns(columns, getSubjectEditUrl) { function getColumns(columns, getSubjectEditUrl) {
var result = []; var result = [];
for (var i = 0; i < columns.length; i++) { for (var i = 0; i < columns.length; i++) {
...@@ -122,7 +145,7 @@ function getColumns(columns, getSubjectEditUrl) { ...@@ -122,7 +145,7 @@ function getColumns(columns, getSubjectEditUrl) {
result.push(createColumn(columnRow.type, columnRow.name, columnRow.filter, columnRow.visible, columnRow.sortable, renderFunction)); result.push(createColumn(columnRow.type, columnRow.name, columnRow.filter, columnRow.visible, columnRow.sortable, renderFunction));
} else { } else {
result.push(createColumn(columnRow.type, columnRow.name, columnRow.filter, columnRow.visible, columnRow.sortable)); result.push(createColumn(columnRow.type, columnRow.name, columnRow.filter, columnRow.visible, columnRow.sortable, createRenderFunction(columnRow)));
} }
} }
return result; return result;
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
.box-body { .box-body {
overflow-x: scroll; overflow-x: scroll;
} }
.highlight_match {
font-weight: bolder;
border-bottom: black 1px solid;
}
</style> </style>
{% endblock styles %} {% endblock styles %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment