how to render datatable inside ajax-modal in openstack horizon dashboard?

↘锁芯ラ 提交于 2019-12-12 02:33:03

问题


i'm beginner in Python Django. according to openstack's customizing horizon dashboard tutorial i've successfully added new panel, tab with datatable. i also added table actions in table class which open ajax-modal. but instead of render form inside that i need to render datatable which should feel up by ajax-response. each row contains form input element (e.g text,radio). but i couldn't figure out how to render datatable inside ajax-modal.

please have a look on tables.py

class AddSwitch(tables.LinkAction):
name = "addswitch"
verbose_name = _("Add Switch")
url = "horizon:project:sdncontroller:addswitch"
classes = ("ajax-modal", "btn-create",)

class Switches(tables.DataTable):
dpid = tables.Column("dpid",verbose_name=_("DPID"))
address = tables.Column('address', verbose_name=_("Address"))
vendor = tables.Column('vendor', verbose_name=_("Vendor"))
packets = tables.Column('packets', verbose_name=_("Packets"))
bytes = tables.Column('bytes', verbose_name=_("Bytes"))
flows = tables.Column('flows', verbose_name=_("Flows"))
connectedsince = tables.Column('connectedsince', verbose_name=_("ConnectedSince"))
detail= tables.Column('details', verbose_name=_("Detail"))

class Meta:
    name = "Switches"
    verbose_name = _("Switches")
    table_actions = (AddSwitch,)

also i've created workflows.py and create class for AddSwitch

class AddSwitch(workflows.Workflow):
slug = "addswitch"
name = _("Add Switch")
finalize_button_name = _("Add")
success_message = _('Added switch "%s".')
failure_message = _('Unable to add switch "%s".')
success_url = "horizon:project:sdncontroller:index"
default_steps = (AddSwitchStep,)

def format_status_message(self, message):
    name = self.context.get('name')
    return message % name

def handle(self, request, context):
    try:
        #api.lbaas.pool_create(request, **context)
        return True
    except Exception:
        return False

this is the point where i stuck. i don't how to code and where to code for rendering datatable and that too fill up dynamically through ajax-response.

Thanks, I hope someone who could lead me into this.


回答1:


You forgot to mention the "columns" attribute in the Class Meta. Please follow the mechanism currently used by Horizon to render the "Instances" data table. You can find the detailed step by step tutorial to create and render a data table here: http://docs.openstack.org/developer/horizon/topics/tutorial.html

Hope it helps



来源:https://stackoverflow.com/questions/21954229/how-to-render-datatable-inside-ajax-modal-in-openstack-horizon-dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!