feat: Enhance DeTable widget with number range filtering and update BaseView for…

… session flash messages
1 parent d8e70b04
......@@ -1152,6 +1152,7 @@ class BaseView(object):
q.delete()
self.db_session.flush()
request.session.flash(msg)
return self.route_list()
form = self.get_form(
self.edit_schema, buttons=(btn_delete, btn_cancel))
......
......@@ -95,7 +95,6 @@ class DeTable(field.Field):
css_class = "deform" # bw compat only; pass a widget to override
def __init__(
self,
schema,
......@@ -485,37 +484,20 @@ class DeTable(field.Field):
html += f'name="{col_id}" id="{col_id}-max" /></span>'
html += f'</div>'
html += f'</div>'
"""
awal
elif getattr(f, "search_method", None) == "yadcf_range_number":
html += f'<div class="form-group" {txt}>'
html += f'<div class="input-group">'
html += f'<span class="input-group-addon">{f.title}</span>'
html += f'<span class="input-group-addon"><input type="date" class="form-control {self.tableid}-control-filter hasDatePicker"'
html += f'data-index={field_index} placeholder="{f.title} Awal" '
html += f'name="{col_id}" id="{col_id}-min"/></span>'
html += f'<span class="input-group-addon"><input type="date" class="form-control {self.tableid}-control-filter hasDatePicker"'
html += f'data-index={field_index} placeholder="{f.title} Akhir" '
html += f'<label class="form-label" style="font-size:12px">{f.title}</label>'
html += f'<div class="input-group" style="padding: 3px 0px 7px !important;">'
html += f'<input type="number" class="form-control {self.tableid}-control-filter"'
html += f'data-index={field_index} placeholder="{f.title} Min" '
html += f'name="{col_id}" id="{col_id}-min"/>'
html += f'<div class="input-group-addon">-</div>'
html += f'<input type="number" class="form-control {self.tableid}-control-filter"'
html += f'data-index={field_index} placeholder="{f.title} Max" '
html += f'name="{col_id}" id="{col_id}-max" /></span>'
html += f'</div>'
html += f'</div>'
"""
# html += """
# <script type="text/javascript">
# deform.addCallback(
# '%s',
# function deform_cb(oid) {
# $('#'+oid).datepicker();
# }
# );
# </script>
# """ % self.tableid
# requirements = f.widget.requirements
# for requirement in requirements:
# if type(requirement) == dict and "js" in requirement:
# for req in requirement:
#
else:
html += f'<input type="text" class="form-control {self.tableid}-control-filter"'
html += f'placeholder="{f.title}" {txt}/>'
......
......@@ -226,6 +226,9 @@
dom: '<"row"<"col-md-8"<"toolbar">>><"row"<"col-md-8"Bl><"col-md-4"fr>>t<"row dt-footer"<"col-md-8 sub-foot" i><"col-md-4"p>>',
processing: true,
serverSide: ${ server_side },
<tal:block tal:condition="filter_columns">
deferLoading: 0,
</tal:block>
data: param_data,
ajax: param_ajax,
stateSave: ${ state_save },
......@@ -422,6 +425,37 @@
//&& min_val !== "" && max_val !== ""
}
}
else if ($(this).attr("type") === 'number') {
value = this.value;
localStorage.setItem(col_id, value);
var splitted = col_id.split('-');
if (splitted[splitted.length - 1] !== "min" && splitted[splitted.length - 1] !== "max"){
o${tableid}.column($(this).data('index')).search(value)
}
else{
var min_val = undefined;
var max_val = undefined;
if (splitted[splitted.length - 1] === "min") {
min_val = this.value;
splitted.length = splitted.length - 1;
col_id = splitted.join("-");
max_val = $("#" + col_id + '-max').val()
}
else {
max_val = this.value;
splitted.length = splitted.length - 1;
col_id = splitted.join("-");
min_val = $("#" + col_id + '-min').val();
}
if (min_val === undefined && max_val !== undefined) min_val = max_val;
if (max_val === undefined && min_val !== undefined) max_val = min_val;
if (max_val !== undefined && min_val !== undefined && min_val !== null && max_val !== null)
o${tableid}
.column($(this).data('index'))
.search(min_val + '-yadcf_delim-' + max_val, true);
//&& min_val !== "" && max_val !== ""
}
}
else {
col_id = this.id;
value = this.value;
......@@ -448,7 +482,7 @@
if (typ === "select") filter_table();
var typ = $(this).attr("type").toLowerCase();
if (typ === "date") filter_table();
if (typ in ("date", "number")) filter_table();
});
console.log("Read Data");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!