Commit 9097cc10 by aa.gusti

perbaikan btn script datatable

1 parent 5436679d
...@@ -125,7 +125,9 @@ class DeTable(field.Field): ...@@ -125,7 +125,9 @@ class DeTable(field.Field):
self.tableid = tableid self.tableid = tableid
self.data = data self.data = data
# Button yang dikirim sebagai tambahan
new_buttons = kw.get("new_buttons") or () new_buttons = kw.get("new_buttons") or ()
action_suffix = f"{action_suffix}{params}"
params = params and f"?{params}" or "" params = params and f"?{params}" or ""
dict_buttons = { dict_buttons = {
...@@ -145,30 +147,22 @@ class DeTable(field.Field): ...@@ -145,30 +147,22 @@ class DeTable(field.Field):
"upload": "{window.location = o%sUri+'/upload%s';}" % ( "upload": "{window.location = o%sUri+'/upload%s';}" % (
tableid, params), tableid, params),
} }
for k in new_buttons: for k in new_buttons:
buttons += (new_buttons[k]["obj"],) buttons += (new_buttons[k]["obj"],)
dict_buttons[k] = '{' + new_buttons[k]["js"].format(tableid=tableid, dict_buttons[k] = '{' + new_buttons[k]["js"].format(tableid=tableid,
params=params) + '}' params=params) + '}'
action_suffix = f"{action_suffix}{params}" obj_buttons = [] # Adalah Header Buttone
_buttons = [] _scripts = []
# buttons = Params Buttons
for button in buttons: for button in buttons:
if isinstance(button, compat.string_types): if isinstance(button, compat.string_types):
button = Button(button) button = Button(button)
_buttons.append(button) obj_buttons.append(button)
buttons = _buttons header_buttons = []
_buttons = [] for button in obj_buttons:
_scripts = [] header_buttons.append(
if filter_columns:
button = f"""
<a href="#{tableid}-form-filter"
data-toggle="collapse"
class= "btn btn-warning dropdown">Filters</a>
"""
_buttons.append(button)
for button in buttons:
_buttons.append(
f"""<button f"""<button
id="{tableid}{button.name}" id="{tableid}{button.name}"
name="{button.name}" name="{button.name}"
...@@ -178,7 +172,16 @@ class DeTable(field.Field): ...@@ -178,7 +172,16 @@ class DeTable(field.Field):
""") """)
_scripts.append(f'$("#{tableid + button.name}").click(function ()' + _scripts.append(f'$("#{tableid + button.name}").click(function ()' +
dict_buttons[button.name] + ');') dict_buttons[button.name] + ');')
self.buttons = "','".join(_buttons).replace('\n', ""). \
if filter_columns:
button = f"""
<a href="#{tableid}-form-filter"
data-toggle="collapse"
class= "btn btn-warning dropdown">Filters</a>
"""
header_buttons.insert(0, button)
self.buttons = "','".join(header_buttons).replace('\n', ""). \
replace(';', ';\n') replace(';', ';\n')
self.tableid = tableid self.tableid = tableid
self.scripts = ''.join(_scripts).replace(';', ";\n") self.scripts = ''.join(_scripts).replace(';', ";\n")
......
...@@ -343,6 +343,8 @@ ...@@ -343,6 +343,8 @@
} }
console.log(col_id, $(this).attr('id'), value); console.log(col_id, $(this).attr('id'), value);
}); });
${structure: btnscripts}
}); });
</script> </script>
</div> </div>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!