【问题标题】:knp paginator sortable in select dropdownknp 分页器可在选择下拉列表中排序
【发布时间】:2019-09-19 04:17:18
【问题描述】:

我将可排序链接布局更改为选择下拉菜单。但是我不知道如何选择选择的选项。

到目前为止,这是我的代码。 我把 sortable.link htwl twig 改成了这个

<option{% for attr, value in options %} {% if attr == 'href' %}value="{{ value }}" {% else %}{{ attr }}="{{ value }}"{% endif %}{% endfor %} >{{ title }}</option>

我的树枝文件看起来像这样:

<select onChange="window.location=this.value;">
{{ knp_pagination_sortable(properties, 'Title A-Z', 'a.title', {}, {'direction': 'asc'}) }}
{{ knp_pagination_sortable(properties, 'Title Z-A', 'a.title', {}, {'direction': 'desc'}) }}
</select>

onchange 下拉菜单有效,但在再次加载时不显示所选选项。请指教 :) 也许这也不是设置选择下拉列表的最佳方式。非常感谢我的代码的任何改进


编辑

我查看了其他模板示例,发现您可以获取方向和顺序,但它不能完全使用 asc/desc 它出错。 这是我更新的选项代码。

<option{% for attr, value in options %} {% if attr == 'href' %}value="{{ value }}" {% else %}{{ attr }}="{{ value }}"{% endif %}{% endfor %}  {% if app.request.get('direction') == 'desc' and app.request.get('sort') == key  %} selected="selected" {% elseif app.request.get('direction') == 'asc' and app.request.get('sort') == key %} selected="selected"{% else%} no{% endif %}>{{ title }}</option>

然后我在树枝上更新了选择

 <select onChange="window.location=this.value;">
    {{ knp_pagination_sortable(properties, 'Title A-Z', 'a.title', {}, {'direction': 'asc'}) }}
    {{ knp_pagination_sortable(properties, 'Title Z-A', 'a.title', {}, {'direction': 'desc'}) }}
    {{ knp_pagination_sortable(properties, 'price (low to high)', 'a.price', {}, {'direction': 'asc'}) }}
    {{ knp_pagination_sortable(properties, 'Price (high to low)', 'a.price', {}, {'direction': 'desc'}) }}
    </select>

感谢您的帮助。谢谢

【问题讨论】:

    标签: symfony select dropdown knppaginator


    【解决方案1】:

    我想我可以回答我自己的问题。 我只需要抓住方向而不是 desc/asc。

    我认为它正在工作:)

    <option{% for attr, value in options %} {% if attr == 'href' %}value="{{ value }}" {% else %}{{ attr }}="{{ value }}"{% endif %}{% endfor %}  {% if app.request.get('direction') == direction and app.request.get('sort') == key  %} selected="selected" {% endif %}>{{ title }}</option>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 2020-06-19
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多