Commit 1200c8be by aa.gusti

detable penambahan paramter filter_columns

1 parent a0632681
...@@ -146,6 +146,7 @@ class BaseView(object): ...@@ -146,6 +146,7 @@ class BaseView(object):
self.allow_unpost = False self.allow_unpost = False
self.state_save = False self.state_save = False
self.list_form = None self.list_form = None
self.filter_columns = False
self.form_scripts = """ self.form_scripts = """
$('#parent_nm').bind('typeahead:selected', function(obj, datum) { $('#parent_nm').bind('typeahead:selected', function(obj, datum) {
...@@ -241,6 +242,7 @@ class BaseView(object): ...@@ -241,6 +242,7 @@ class BaseView(object):
allow_post = kwargs.get("allow_post", self.allow_post) allow_post = kwargs.get("allow_post", self.allow_post)
allow_unpost = kwargs.get("allow_unpost", self.allow_unpost) allow_unpost = kwargs.get("allow_unpost", self.allow_unpost)
state_save = kwargs.get("state_save", self.state_save) state_save = kwargs.get("state_save", self.state_save)
filter_columns = kwargs.get("filter_columns", self.filter_columns)
schema = self.list_schema() schema = self.list_schema()
schema = schema.bind(request=self.req) schema = schema.bind(request=self.req)
list_url = kwargs.get("list_url", None) list_url = kwargs.get("list_url", None)
...@@ -263,7 +265,7 @@ class BaseView(object): ...@@ -263,7 +265,7 @@ class BaseView(object):
allow_unpost=allow_unpost, allow_unpost=allow_unpost,
state_save=state_save, state_save=state_save,
new_buttons=new_buttons, new_buttons=new_buttons,
form=self.list_form, filter_columns=filter_columns,
) )
resources = table.get_widget_resources() resources = table.get_widget_resources()
# resources=dict(css="", js="") # resources=dict(css="", js="")
......
...@@ -116,8 +116,7 @@ class DeTable(field.Field): ...@@ -116,8 +116,7 @@ class DeTable(field.Field):
allow_view=True, allow_view=True,
allow_post=False, allow_post=False,
allow_unpost=False, allow_unpost=False,
form=None, filter_columns=False,
form_object=False,
**kw **kw
): ):
# field.Field.__init__(self, schema, **kw) # field.Field.__init__(self, schema, **kw)
...@@ -178,6 +177,7 @@ class DeTable(field.Field): ...@@ -178,6 +177,7 @@ class DeTable(field.Field):
self.allow_view = json.dumps(allow_view) self.allow_view = json.dumps(allow_view)
self.allow_post = json.dumps(allow_post) self.allow_post = json.dumps(allow_post)
self.allow_unpost = json.dumps(allow_unpost) self.allow_unpost = json.dumps(allow_unpost)
self.filter_columns = json.dumps(filter_columns)
table_widget = getattr(schema, "widget", None) table_widget = getattr(schema, "widget", None)
if table_widget is None: if table_widget is None:
table_widget = widget.TableWidget() table_widget = widget.TableWidget()
...@@ -246,11 +246,6 @@ class DeTable(field.Field): ...@@ -246,11 +246,6 @@ class DeTable(field.Field):
headers.append(f.title) headers.append(f.title)
cols2.append(data) cols2.append(data)
if form:
form = Form(form())
if not form_object:
form = form.render()
self.headers = headers self.headers = headers
self.head = headers self.head = headers
self.columns = json.dumps(columns) self.columns = json.dumps(columns)
...@@ -262,7 +257,6 @@ class DeTable(field.Field): ...@@ -262,7 +257,6 @@ class DeTable(field.Field):
self.paginates = paginates self.paginates = paginates
self.filters = filters self.filters = filters
self.state_save = json.dumps(state_save) self.state_save = json.dumps(state_save)
self.form = form
class Button(object): class Button(object):
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
allow_post allow_post|field.allow_post; allow_post allow_post|field.allow_post;
allow_unpost allow_unpost|field.allow_unpost; allow_unpost allow_unpost|field.allow_unpost;
state_save state_save|field.state_save; 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|{};" tal:attributes="style style; class css_class; attributes|field.widget.attributes|{};"
i18n:domain="detable" i18n:domain="detable"
...@@ -37,18 +37,26 @@ ...@@ -37,18 +37,26 @@
</div> </div>
<div role="content"> <div role="content">
<div class="widget-body"> <div class="widget-body">
<table <table tal:condition="filter_columns" id="${tableid}-form-filter">
id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead> <thead>
<tr> <tr tal:repeat="child field">
<th colspan="${next(field.counter)-1}" tal:condition="form">${structure: form}</th> <th>${child.title}</th>
</tr> </tr>
</thead>
</table>
<table id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead>
<tr> <tr>
<th tal:repeat="child field">${child.title}</th> <th tal:repeat="child field">${child.title}</th>
</tr> </tr>
</thead> </thead>
<tbody></tbody> <tbody></tbody>
<tfoot>
<th tal:repeat="child field">${child.title}</th>
</tfoot>
</table> </table>
</div> </div>
<!-- widget-body --> <!-- widget-body -->
...@@ -69,10 +77,7 @@ ...@@ -69,10 +77,7 @@
var o${tableid}Uri = "${url}"; var o${tableid}Uri = "${url}";
var o${tableid}Url = o${tableid}Uri + "${url_suffix}"; var o${tableid}Url = o${tableid}Uri + "${url_suffix}";
var m${tableid}ID; var m${tableid}ID;
deform.addCallback deform.addCallback('${tableid}', function (oid) {
('${tableid}', function (oid) {
// $(document).ready(function () {
function displayEmptyID() { function displayEmptyID() {
$("#emptyID").show(); $("#emptyID").show();
$('#emptyID').animate({opacity: 0.8}, 2000); $('#emptyID').animate({opacity: 0.8}, 2000);
...@@ -90,6 +95,7 @@ ...@@ -90,6 +95,7 @@
' &nbsp;', ' &nbsp;',
'</div>', '</div>',
] ]
let ${tableid}Columns = ${structure: columns}; let ${tableid}Columns = ${structure: columns};
function render_checkbox(value) { function render_checkbox(value) {
...@@ -169,6 +175,7 @@ ...@@ -169,6 +175,7 @@
}, },
"lengthMenu": " _MENU_ baris " "lengthMenu": " _MENU_ baris "
}; };
let ${tableid}Params = { let ${tableid}Params = {
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,
...@@ -186,16 +193,49 @@ ...@@ -186,16 +193,49 @@
[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 () {
$('.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}) { if (!${server_side}) {
${tableid}Params.data = ${data}; ${tableid}Params.data = ${data};
} else { } else {
${tableid}Params.ajax = o${tableid}Url; ${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); o${tableid} = $('#${tableid}').DataTable(${tableid}Params);
let tb = tb_array.join(' '); let tb = tb_array.join(' ');
$("div.toolbar").html(tb); $("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!