【问题标题】:Filter Datagrid onLoad过滤 Datagrid onLoad
【发布时间】:2011-02-12 02:26:45
【问题描述】:

当我从下拉列表中选择一个月时,我的数据网格成功过滤,但是当我尝试在加载时过滤它时,它只是没有过滤。下拉菜单成功显示当前月份,网格也应该显示当前月份数据。

 <script type="text/javascript">
        dojo.require("dojox.grid.DataGrid");
        dojo.require("dojox.data.XmlStore");
        dojo.require("dijit.form.FilteringSelect");
        dojo.require("dojo.data.ItemFileReadStore");
        dojo.require("dojo.date");

        theMonth = new Date();

        dojo.addOnLoad(function()
            {
                dojo.byId('monthInput').value = month_name[(theMonth.getMonth()+1)];
                var filterString='{month: "' + theMonth.getMonth() + '"}';
                var filterObject=eval('('+filterString+')');
                dijit.byId("eventGrid").filter(filterObject);
            }
        );

        var eventStore = new dojox.data.XmlStore({url: "events.xml", rootItem: "event", keyAttribute: "dateSort"});

        function monthClick() { 
            var ctr, test, rtrn;

            test = dojo.byId('monthInput').value;

            for (ctr=0;ctr<=11;ctr++)
            {
                if (test==month_name[ctr])
                {
                    rtrn = ctr;
                }
            }

            var filterString='{month: "' + rtrn + '"}';
            var filterObject=eval('('+filterString+')');

            eventGrid.setQuery(filterObject);
        }

    </script>
</head>
<body class="tundra">
   <div id="header" dojoType="dijit.layout.ContentPane" region="top" class="pfga"></div>
   <div id="menu" dojoType="dijit.layout.ContentPane" region="left" class="pfga"></div>

   <div id="content" style="width:750px; overflow:visible" dojoType="dijit.layout.ContentPane" region="center" class="pfga">
        <div dojotype="dojo.data.ItemFileReadStore" url="months.json" jsID="monthStore"></div>

        <div id="pagehead" class="Heading1" >Upcoming Events</div>
        <p>
        <input dojoType="dijit.form.FilteringSelect" store="monthStore" searchAttr="month" name="id" id="monthInput" class="pfga" onChange="monthClick()" />
        </p>
        <table dojoType="dojox.grid.DataGrid" store="eventStore" class="pfga" style="height:500px; width:698px" clientSort="true" jsID="eventGrid">
          <thead>
            <tr>
              <th field="date" width="80px">Date</th>
              <th field="description" width="600px">Description</th>
            </tr>
            <tr>
                <th field="time" colspan="2">Details</th>
            </tr>
          </thead>
        </table>

   </div>     

   <div id="footer"></div>

【问题讨论】:

    标签: datagrid filter dojo


    【解决方案1】:

    这可能是一个异步问题。也就是说,您的 addOnLoad 执行是因为 DOM 已加载,但您的数据尚未完成加载。您可以尝试将您的月份过滤逻辑连接到以下而不是 addOnLoad 吗?也许它看起来像这样:

     dojo.connect(eventGrid, "_onFetchComplete", function(){
                    dojo.byId('monthInput').value = month_name[(theMonth.getMonth()+1)];
                    var filterString='{month: "' + theMonth.getMonth() + '"}';
                    var filterObject=eval('('+filterString+')');
                    dijit.byId("eventGrid").filter(filterObject);
                });
    

    【讨论】:

    • 谢谢你的想法,我试过了,但没用。当我在 addOnLoad 中有这个时,设置 monthInput 下拉列表的部分确实将下拉列表设置为当前月份。这段代码甚至没有这样做。到目前为止,我有一个解决方法,即在加载时它只显示所有数据,并且我添加了一个月列。当用户点击下拉菜单并对其进行排序时,它也会隐藏月份列。
    【解决方案2】:

    filter() 是客户端过滤。它应该在构建网格并加载数据后调用。

    您要设置网格的查询参数。这决定了存储中的哪些记录进入网格。它类似于“从表中选择 *”。

    Filter 用于过滤这些结果,因此当用户从您的客户端过滤中进行选择时调用 filter。过滤器类似于在“从表中选择 *”中添加 where 子句。

    【讨论】:

    • 是的,当我尝试使用客户端过滤时,网格已构建并加载数据,但它根本不起作用。
    猜你喜欢
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 2016-05-28
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多