Commit 1200c8be by aa.gusti

detable penambahan paramter filter_columns

1 parent a0632681
......@@ -146,6 +146,7 @@ class BaseView(object):
self.allow_unpost = False
self.state_save = False
self.list_form = None
self.filter_columns = False
self.form_scripts = """
$('#parent_nm').bind('typeahead:selected', function(obj, datum) {
......@@ -241,6 +242,7 @@ class BaseView(object):
allow_post = kwargs.get("allow_post", self.allow_post)
allow_unpost = kwargs.get("allow_unpost", self.allow_unpost)
state_save = kwargs.get("state_save", self.state_save)
filter_columns = kwargs.get("filter_columns", self.filter_columns)
schema = self.list_schema()
schema = schema.bind(request=self.req)
list_url = kwargs.get("list_url", None)
......@@ -263,7 +265,7 @@ class BaseView(object):
allow_unpost=allow_unpost,
state_save=state_save,
new_buttons=new_buttons,
form=self.list_form,
filter_columns=filter_columns,
)
resources = table.get_widget_resources()
# resources=dict(css="", js="")
......
......@@ -116,8 +116,7 @@ class DeTable(field.Field):
allow_view=True,
allow_post=False,
allow_unpost=False,
form=None,
form_object=False,
filter_columns=False,
**kw
):
# field.Field.__init__(self, schema, **kw)
......@@ -178,6 +177,7 @@ class DeTable(field.Field):
self.allow_view = json.dumps(allow_view)
self.allow_post = json.dumps(allow_post)
self.allow_unpost = json.dumps(allow_unpost)
self.filter_columns = json.dumps(filter_columns)
table_widget = getattr(schema, "widget", None)
if table_widget is None:
table_widget = widget.TableWidget()
......@@ -246,11 +246,6 @@ class DeTable(field.Field):
headers.append(f.title)
cols2.append(data)
if form:
form = Form(form())
if not form_object:
form = form.render()
self.headers = headers
self.head = headers
self.columns = json.dumps(columns)
......@@ -262,7 +257,6 @@ class DeTable(field.Field):
self.paginates = paginates
self.filters = filters
self.state_save = json.dumps(state_save)
self.form = form
class Button(object):
......
......@@ -22,7 +22,7 @@
allow_post allow_post|field.allow_post;
allow_unpost allow_unpost|field.allow_unpost;
state_save state_save|field.state_save;
form form|field.form;
filter_columns filter_columns|field.filter_columns;
"
tal:attributes="style style; class css_class; attributes|field.widget.attributes|{};"
i18n:domain="detable"
......@@ -37,18 +37,26 @@
</div>
<div role="content">
<div class="widget-body">
<table
id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer">
<table tal:condition="filter_columns" id="${tableid}-form-filter">
<thead>
<tr>
<th colspan="${next(field.counter)-1}" tal:condition="form">${structure: form}</th>
<tr tal:repeat="child field">
<th>${child.title}</th>
</tr>
</thead>
</table>
<table id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead>
<tr>
<th tal:repeat="child field">${child.title}</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<th tal:repeat="child field">${child.title}</th>
</tfoot>
</table>
</div>
<!-- widget-body -->
......@@ -69,10 +77,7 @@
var o${tableid}Uri = "${url}";
var o${tableid}Url = o${tableid}Uri + "${url_suffix}";
var m${tableid}ID;
deform.addCallback
('${tableid}', function (oid) {
// $(document).ready(function () {
deform.addCallback('${tableid}', function (oid) {
function displayEmptyID() {
$("#emptyID").show();
$('#emptyID').animate({opacity: 0.8}, 2000);
......@@ -90,6 +95,7 @@
' &nbsp;',
'</div>',
]
let ${tableid}Columns = ${structure: columns};
function render_checkbox(value) {
......@@ -169,6 +175,7 @@
},
"lengthMenu": " _MENU_ baris "
};
let ${tableid}Params = {
dom: '<"row"<"col-md-8"<"toolbar">Bl><"col-md-4"fr>>tip',
processing: true,
......@@ -186,16 +193,49 @@
[10, 25, 50, 100],
[10, 25, 50, 100]
],
"pageLength": 25,
pageLength: 25,
columns: ${tableid}Columns,
"language": ${tableid}Language,
language: ${tableid}Language,
initComplete: function () {
$('.dataTables_filter input').unbind()
.bind('keyup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
o${tableid}.search(this.value).draw();
}
});
}
}
if (!${server_side}) {
${tableid}Params.data = ${data};
} else {
${tableid}Params.ajax = o${tableid}Url;
}
<tal:block tal:condition="filter_columns">
$('#${tableid}-form-filter thead th').each(function (i) {
console.log($(this).index());
var title = $(this).text();
// var title = $('#${tableid}-form-filter thead th')
// .eq($(this).index())
// .text();
$(this).html(
'<input type="text" placeholder="' + title + '" data-index="' + i + '" />'
);
});
$("#${tableid}-form-filter").on('keyup', 'th input', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
o${tableid}
.column($(this).data('index'))
.search(this.value)
.draw();
}
});
</tal:block>
o${tableid} = $('#${tableid}').DataTable(${tableid}Params);
let tb = tb_array.join(' ');
$("div.toolbar").html(tb);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!