Commit b705d457 by aa.gusti

perbaikan detable

1 parent 808b8a58
...@@ -430,9 +430,8 @@ class BaseView(object): ...@@ -430,9 +430,8 @@ class BaseView(object):
if k in select_list.keys(): if k in select_list.keys():
vals = select_list[k] vals = select_list[k]
for r in vals: for r in vals:
if r[0] == res[k]: if r and str(r) == str(res[k]):
res[k] = r[1] res[k] = vals[r]
""
# for k, v in d.items(): # for k, v in d.items():
# if k in url and v: # if k in url and v:
# link = "/".join([self.home, nik_url, v]) # link = "/".join([self.home, nik_url, v])
......
...@@ -428,7 +428,7 @@ class DeTable(field.Field): ...@@ -428,7 +428,7 @@ class DeTable(field.Field):
html += f'placeholder="{f.title}" {txt}/>' html += f'placeholder="{f.title}" {txt}/>'
html += '<option value="">Semua</option>' html += '<option value="">Semua</option>'
if type(wg_select_val) == list: if type(wg_select_val) == list:
wg_select_val = dict(list) wg_select_val = dict(wg_select_val)
for key in wg_select_val: for key in wg_select_val:
html += f'<option value="{key}">{wg_select_val[key]}</option>' html += f'<option value="{key}">{wg_select_val[key]}</option>'
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<div class="row" tal:condition="filter_columns"> <div class="row" tal:condition="filter_columns">
<div id="${tableid}-form-filter-container" class="col-md-3"> <div id="${tableid}-form-filter-container" class="col-md-3">
<div id="${tableid}-form-filter" class="collapse"> <div id="${tableid}-form-filter" class="collapse">
${structure:filter_form} ${structure:filter_form}
</div> </div>
</div> </div>
</div> </div>
...@@ -65,20 +65,20 @@ ...@@ -65,20 +65,20 @@
}); });
</script> </script>
</div> </div>
<table id="${tableid}" class="table table-bordered table-hover table-condensed dataTable no-footer"> <table id="${tableid}" class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead> <thead>
<tr> <tr>
<tr> <tr>
<tal:block tal:repeat="child field"> <tal:block tal:repeat="child field">
<tal:block tal:condition="python:not hasattr(child, 'visible') or getattr(child, 'visible')==True"> <tal:block tal:condition="python:not hasattr(child, 'visible') or getattr(child, 'visible')==True">
<th <th
tal:condition="python:hasattr(child, 'action') and not getattr(child.condition)==False and False or True"> tal:condition="python:hasattr(child, 'action') and not getattr(child.condition)==False and False or True">
${child.title} </th> ${child.title} </th>
</tal:block>
</tal:block> </tal:block>
</tr> </tal:block>
</tr>
</thead> </thead>
<tbody></tbody> <tbody></tbody>
...@@ -110,13 +110,13 @@ ...@@ -110,13 +110,13 @@
function displayEmptyID() { function displayEmptyID() {
$("#emptyID").show(); $("#emptyID").show();
$('#emptyID').animate({ opacity: 0.8 }, 2000); $('#emptyID').animate({opacity: 0.8}, 2000);
setTimeout(function () { setTimeout(function () {
$("#emptyID").fadeTo(500, 0).slideUp(500, function () { $("#emptyID").fadeTo(500, 0).slideUp(500, function () {
$("#emptyID").hide(); $("#emptyID").hide();
}); });
} }
, 4000); , 4000);
} }
let tb_array = [ let tb_array = [
...@@ -154,149 +154,144 @@ ...@@ -154,149 +154,144 @@
function render_checklist(value) { function render_checklist(value) {
return '<input type="checkbox" class="${tableid}_check" checked="' + { value } + '"></input>'; return '<input type="checkbox" class="${tableid}_check" checked="' + {value} + '"></input>';
} }
for (let co in ${tableid}Columns) { for (let co in ${tableid}Columns) {
if (${tableid}Columns[co].wg_checkbox === true) { if (${tableid}Columns[co].wg_checkbox === true) {
${tableid}Columns[co].render = function (value) { ${tableid}Columns[co].render = function (value) {
if (typeof value === "string" && value.length > 0) { if (typeof value === "string" && value.length > 0) {
return render_checkbox(value) return render_checkbox(value)
} }
if (["", false, 0, null].indexOf(value) === -1) { if (["", false, 0, null].indexOf(value) === -1) {
return render_checkbox(true); return render_checkbox(true);
}
return render_checkbox(false);
} }
return render_checkbox(false); //}
} //else if (${tableid}Columns[co].wg_select === true) {
} else if (${tableid}Columns[co].wg_select === true) { // ${tableid}Columns[co].render = function (value) {
${tableid}Columns[co].render = function (value) { // if (value != null)
if (value!=null) // return ${tableid}Columns[co].wg_select_val[value];
return ${tableid}Columns[co].wg_select_val[value]; // return "";
return ""; // }
} } else if (${tableid}Columns[co].hasOwnProperty("url")) {
} else if (${tableid}Columns[co].hasOwnProperty("url")) { let url = ${tableid}Columns[co].url;
let url = ${tableid}Columns[co].url;
${tableid}Columns[co].render = function (data) { ${tableid}Columns[co].render = function (data) {
let result = "No Data"; let result = "No Data";
if (data != null) { if (data != null) {
result = '<a href="' + url + data + '" target="_blank">Link</a>&nbsp;'; result = '<a href="' + url + data + '" target="_blank">Link</a>&nbsp;';
}
return result;
} }
return result; } else if (${tableid}Columns[co].data === "id") {
}
} else if (${tableid}Columns[co].data === "id") {
${tableid}Columns[co].render = function (id, typ, data, setting) { ${tableid}Columns[co].render = function (id, typ, data, setting) {
if (${tableid}Columns[co].action === false) return "" if (${tableid}Columns[co].action === false) return ""
let result = ""; let result = "";
if (${allow_check}) { if (${allow_check}) {
var checked = ""; var checked = "";
if (check_field !== "") { if (check_field !== "") {
checked = data[check_field] !== null ? "checked" : ""; checked = data[check_field] !== null ? "checked" : "";
m${tableid}CheckList.push(id); m${tableid}CheckList.push(id);
}
var mtableId = "${tableid}";
result = '<input type="checkbox" class="' + mtableId + '_check" value="' + id + '" ' + checked + ' name="' + mtableId + '_check"/>&nbsp;';
} }
var mtableId = "${tableid}"; if (${allow_view})
result = '<input type="checkbox" class="' + mtableId + '_check" value="' + id + '" ' + checked + ' name="' + mtableId + '_check"/>&nbsp;'; result += '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;';
}
if (${allow_view})
result += '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;';
if (${allow_edit}) if (${allow_edit})
result += '<a href="${url}/' + id + '/edit"><i class="fas fa-edit" aria-hidden="true" title="Edit"></i></a>&nbsp;' result += '<a href="${url}/' + id + '/edit"><i class="fas fa-edit" aria-hidden="true" title="Edit"></i></a>&nbsp;'
if (${allow_delete}) if (${allow_delete})
result += '<a href="${url}/' + id + '/delete"><i class="fas fa-trash" aria-hidden="true" title="Delete"></i></a>'; result += '<a href="${url}/' + id + '/delete"><i class="fas fa-trash" aria-hidden="true" title="Delete"></i></a>';
if (${allow_post}) if (${allow_post})
result += '<a href="${url}/' + id + '/post"><i class="fas fa-signs-post" aria-hidden="true" title="Post"></i></a>'; result += '<a href="${url}/' + id + '/post"><i class="fas fa-signs-post" aria-hidden="true" title="Post"></i></a>';
if (${allow_unpost}) if (${allow_unpost})
result += '<a href="${url}/' + id + '/unpost"><i class="fas fa-delete-left" aria-hidden="true" title="Unpost"></i></a>'; result += '<a href="${url}/' + id + '/unpost"><i class="fas fa-delete-left" aria-hidden="true" title="Unpost"></i></a>';
return result; return result;
}
//columns[1].order = "order_asc";
} }
//columns[1].order = "order_asc";
} }
}
let ${tableid}Params = {}
var param_ajax = "";
var param_data = "";
if (!${server_side}) {
param_data = ${data};
param_ajax = "";
} else {
param_ajax = o${tableid}Url;
param_data = [];
}
let ${tableid}Params = {}
var param_ajax = "";
var param_data = [];
if (!${server_side}) {
param_data = ${data};
} else {
param_ajax = o${tableid}Url;
}
o${tableid} = $('#${tableid}').DataTable({ o${tableid} = $('#${tableid}').DataTable({
scrollX: ${field.scroll_x}, scrollX: ${field.scroll_x},
//scrollY: ${field.scroll_y}, //scrollY: ${field.scroll_y},
dom: '<"row"<"col-md-8"<"toolbar">Bl><"col-md-4"fr>>tip', dom: '<"row"<"col-md-8"<"toolbar">Bl><"col-md-4"fr>>tip',
processing: true, processing: true,
serverSide: ${server_side}, serverSide: ${server_side},
data: param_data, data: param_data,
ajax: param_ajax, ajax: param_ajax,
stateSave: ${state_save}, stateSave: ${state_save},
scrollCollapse: true, scrollCollapse: true,
sort: ${sorts}, sort: ${sorts},
info: true, info: true,
filter: ${filters}, filter: ${filters},
autoWidth: false, autoWidth: false,
paginate: ${paginates}, paginate: ${paginates},
paginationType: "full_numbers", paginationType: "full_numbers",
order: [], order: [],
lengthMenu: [ lengthMenu: [
[10, 25, 50, 100], [10, 25, 50, 100],
[10, 25, 50, 100] [10, 25, 50, 100]
], ],
pageLength: 25, pageLength: 25,
columns: ${tableid}Columns, columns: ${tableid}Columns,
language: ${tableid}Language, language: ${tableid}Language,
initComplete: function () { initComplete: function () {
$('.dataTables_filter input').unbind() $('.dataTables_filter input').unbind()
.bind('keyup', function (e) { .bind('keyup', function (e) {
var code = e.keyCode || e.which; var code = e.keyCode || e.which;
if (code === 13) { if (code === 13) {
o${tableid}.search(this.value).draw(); o${tableid}.search(this.value).draw();
}
});
} }
});
}
} }
); );
let tb = tb_array.join(' '); let tb = tb_array.join(' ');
$("div.toolbar").html(tb); $("div.toolbar").html(tb);
$("div.toolbar").attr('style', 'display:block; float: left; margin-bottom:6px; line-height:16px;'); $("div.toolbar").attr('style', 'display:block; float: left; margin-bottom:6px; line-height:16px;');
$('#${tableid} tbody').on('click', ':checkbox', function () { $('#${tableid} tbody').on('click', ':checkbox', function () {
if (this.checked) m${tableid}CheckList.push($(this).val()); if (this.checked) m${tableid}CheckList.push($(this).val());
else m${tableid}CheckList.splice(m${tableid}CheckList.indexOf($(this).val()), 1); else m${tableid}CheckList.splice(m${tableid}CheckList.indexOf($(this).val()), 1);
}); });
$('#${tableid} tbody').on('click', 'tr', function () { $('#${tableid} tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) { if ($(this).hasClass('selected')) {
$(this).removeClass('selected'); $(this).removeClass('selected');
m${tableid}ID = null; m${tableid}ID = null;
} else { } else {
let aData = o${tableid}.row(this).data(); let aData = o${tableid}.row(this).data();
o${tableid}.$('tr.selected').removeClass('selected'); o${tableid}.$('tr.selected').removeClass('selected');
$(this).addClass('selected'); $(this).addClass('selected');
m${tableid}ID = aData.id; m${tableid}ID = aData.id;
o${tableid}.$('tr.row_selected').removeClass('row_selected'); o${tableid}.$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected'); $(this).addClass('row_selected');
} }
}); });
<tal:block tal:condition="filter_columns"> <tal:block tal:condition="filter_columns">
$(".${tableid}-control-filter").on('keyup', function (e) { $(".${tableid}-control-filter").on('keyup', function (e) {
var code = e.keyCode || e.which; var code = e.keyCode || e.which;
if (code === 13) { if (code === 13) filter_table();
filter_table()
}
}); });
function filter_table() { function filter_table() {
...@@ -313,89 +308,95 @@ ...@@ -313,89 +308,95 @@
localStorage.setItem(col_id, value); localStorage.setItem(col_id, value);
o${tableid} o${tableid}
.column($(this).data('index')) .column($(this).data('index'))
.search(this.value) .search(this.value)
} }
} else if ($(this).attr("type") === 'date') { }
value = this.value; else if ($(this).attr("type") === 'date') {
localStorage.setItem(col_id, value); value = this.value;
var splitted = col_id.split('-'); localStorage.setItem(col_id, value);
var min_val = undefined; var splitted = col_id.split('-');
var max_val = undefined; var min_val = undefined;
if (splitted[splitted.length - 1] === "min") { var max_val = undefined;
min_val = this.value; if (splitted[splitted.length - 1] === "min") {
splitted.length = splitted.length - 1; min_val = this.value;
col_id = splitted.join("-"); splitted.length = splitted.length - 1;
max_val = $("#" + col_id + '-max').val() col_id = splitted.join("-");
max_val = $("#" + col_id + '-max').val()
} else { } else {
max_val = this.value; max_val = this.value;
splitted.length = splitted.length - 1; splitted.length = splitted.length - 1;
col_id = splitted.join("-"); col_id = splitted.join("-");
min_val = $("#" + col_id + '-min').val() min_val = $("#" + col_id + '-min').val()
} }
if (min_val === undefined && max_val !== undefined) if (min_val === undefined && max_val !== undefined)
min_val = max_val; min_val = max_val;
if (max_val === undefined && min_val !== undefined) if (max_val === undefined && min_val !== undefined)
max_val = min_val; max_val = min_val;
if (max_val !== undefined && min_val !== undefined && min_val !== "" && max_val !== "" && min_val !== null && max_val !== null) if (max_val !== undefined && min_val !== undefined && min_val !== "" && max_val !== "" && min_val !== null && max_val !== null)
o${tableid} o${tableid}
.column($(this).data('index')) .column($(this).data('index'))
.search(min_val + '-yadcf_delim-' + max_val, true) .search(min_val + '-yadcf_delim-' + max_val, true)
} else { }
col_id = this.id; else {
value = this.value; col_id = this.id;
if (value === undefined || value === null) { value = this.value;
value = ""; if (value === undefined || value === null) {
value = "";
} }
console.log(col_id, $(this).attr('id'), value, $(this).data('index')); console.log(col_id, $(this).attr('id'), value, $(this).data('index'));
localStorage.setItem(col_id, value); localStorage.setItem(col_id, value);
o${tableid} o${tableid}
.column($(this).data('index')) .column($(this).data('index'))
.search(value); .search(value);
} }
}); });
o${tableid}.draw(); //o${tableid}.ajax.url(o${tableid}Url).load();
o${tableid}.draw();
} }
$(".${tableid}-control-filter").on('click', function (e) { $(".${tableid}-control-filter").on('click', function (e) {
console.log("Write Data Click"); console.log("Write Data Click");
var typ = $(this).attr("type"); var typ = $(this).attr("type");
if (typ === 'radio') { if (typ === 'radio') {
filter_table() filter_table();
} }
}); });
$(".${tableid}-control-filter").on('change', function (e) { $(".${tableid}-control-filter").on('change', function (e) {
var typ = $(this).prop("nodeName").toLowerCase(); var typ = $(this).prop("nodeName").toLowerCase();
if (typ === "select") { if (typ === "select") {
filter_table() filter_table()
} }
var typ = $(this).attr("type").toLowerCase();
if (typ === "date") { var typ = $(this).attr("type").toLowerCase();
filter_table() if (typ === "date") {
} filter_table();
}
}); });
console.log("Read Data"); console.log("Read Data");
$(".${tableid}-control-filter").each(function (e) { $(".${tableid}-control-filter").each(function (e) {
var col_id = $(this).attr("id") var col_id = $(this).attr("id")
var value; var value;
if ($(this).attr("type") === 'radio') { if ($(this).attr("type") === 'radio') {
col_id = $(this).attr('id').split("-"); col_id = $(this).attr('id').split("-");
col_id.length = 2; col_id.length = 2;
col_id = col_id.join("-"); col_id = col_id.join("-");
value = localStorage.getItem(col_id); value = localStorage.getItem(col_id);
if (value !== undefined && value != null) if (value !== undefined && value != null)
if ($(this).val() === value) $(this).attr("checked", true); if ($(this).val() === value) $(this).attr("checked", true);
else $(this).attr("checked", false); else $(this).attr("checked", false);
} else { } else {
value = localStorage.getItem(col_id); value = localStorage.getItem(col_id);
if (value !== undefined && value !== null) if (value !== undefined && value !== null)
$(this).val(value); $(this).val(value);
} }
console.log(col_id, $(this).attr('id'), value); //console.log(col_id, $(this).attr('id'), value);
}); });
filter_table(); filter_table();
</tal:block>
</tal:block>
${structure: btnscripts} ${structure: btnscripts}
${structure: filter_scripts} ${structure: filter_scripts}
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!