如何在openstack地平线仪表板中的ajax-modal内部渲染datatable? [英] how to render datatable inside ajax-modal in openstack horizon dashboard?

查看:188
本文介绍了如何在openstack地平线仪表板中的ajax-modal内部渲染datatable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python Django的初学者。根据openstack的定制天际仪表板教程,我已经成功地添加了新的面板,标签与datatable。我还在打开ajax-modal的表类中添加了表操作。但是,我不需要渲染表单,我需要渲染datatable应该感觉到ajax响应。每行包含表单输入元素(例如文本,无线电)。但我无法弄清楚如何在ajax-modal中渲染datatable。



请查看tables.py

  class AddSwitch(tables $ link 
name =addswitch
verbose_name = _(Add Switch)
url =horizo​​n:project:sdncontroller:addswitch
classes =(ajax -

$ b class开关(tables.DataTable):
dpid = tables.Column(dpid,verbose_name = _(DPID))
address = tables.Column('address',verbose_name = _(Address))
vendor = tables.Column('vendor',verbose_name = _(Vendor))
packet = tables.Column('packets',verbose_name = _(Packets))
bytes = tables.Column('bytes',verbose_name = _(Bytes))
flows = tables。列('streams',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)

我还创建了workflows.py并为AddSwitch创建了类

  class AddSwitch(workflows.Workflow):
slug =addswitch
name = _(Add Switch)
finalize_button_name = _(Add)
success_message = _('added switch%s。)
failure_message = _('无法添加开关'%s。)
success_url =horizo​​n:project:sdncontroller:index
default_steps =(AddSwitchStep,)

def format_status_message(self,message):
name = self.context.get('名称')
返回消息%name

def handle(self,request,context):
try:
#api.lbaas.pool_create(request,**上下文)
返回True
除了异常:
返回False

这是我卡住的地步。我不知道如何编写代码,并在哪里编写渲染数据表,并且通过ajax响应动态填充。



谢谢,我希望有人能带我进去这个。

解决方案

你忘了在Class Meta中提到列属性。请遵循Horizo​​n当前使用的机制来呈现Instances数据表。您可以在这里找到详细的逐步教程来创建和呈现数据表: http ://docs.openstack.org/developer/horizo​​n/topics/tutorial.html



希望有帮助


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.

解决方案

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

这篇关于如何在openstack地平线仪表板中的ajax-modal内部渲染datatable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆