在jqgrid中使用columnchooser(一个有可用列/添加列)我是否需要添加任何js或插件?

时间:2016-03-15 07:48:57

标签: jquery jqgrid

我尝试使用.columnchooser()。但是我没有得到这个设计。它有一列而不是两列。

我想要以下链接:
http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWithColumnChooser5__.htm

这是我的代码。

<table id="grid"></table>
<div id="pager"></div>
<h2>Index</h2>
<link href="~/Scripts/local/jquery-ui.min.css" rel="stylesheet" />
<script src="~/Scripts/local/jquery-1.11.3.min.js"></script>
<script src="~/Scripts/local/jquery-ui-1.11.4.min.js"></script>
<link href="~/Scripts/local/ui.multiselect.css" rel="stylesheet" />
<script src="~/Scripts/local/ui.multiselect.js"></script>
<link href="~/Scripts/local/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/local/grid.locale-en.js"></script>
<script src="~/Scripts/local/jquery.jqGrid.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {        
            "use strict";
            var mydata = [
                    { id: "10", invdate: "2015-10-01", name: "test", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "20", invdate: "2015-09-01", name: "test2", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "30", invdate: "2015-09-01", name: "test3", amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                    { id: "40", invdate: "2015-10-04", name: "test4", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
                    { id: "50", invdate: "2015-10-31", name: "test5", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "60", invdate: "2015-09-06", name: "test6", amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                    { id: "70", invdate: "2015-10-04", name: "test7", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
                    { id: "80", invdate: "2015-10-03", name: "test8", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "90", invdate: "2015-09-01", name: "test9", amount: "400.00", tax: "30.00", closed: false, ship_via: "TN", total: "430.00" },
                    { id: "100", invdate: "2015-09-08", name: "test10", amount: "500.00", tax: "30.00", closed: true, ship_via: "TN", total: "530.00" },
                    { id: "110", invdate: "2015-09-08", name: "test11", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" },
                    { id: "120", invdate: "2015-09-10", name: "test12", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" }
            ],
                numberTemplate = {
                    formatter: "number", align: "right", sorttype: "number",
                    searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
                };
            $("#grid").jqGrid({
                colModel: [
                    { name: "name", label: "Client", width: 53 },
                    {
                        name: "invdate", label: "Date", width: 75, align: "center", sorttype: "date",
                        formatter: "date", formatoptions: { newformat: "d-M-Y" }
                    },
                    { name: "amount", label: "Amount", width: 65, template: numberTemplate },
                    { name: "tax", label: "Tax", width: 41, template: numberTemplate },
                    { name: "total", label: "Total", width: 51, template: numberTemplate },
                    {
                        name: "closed", label: "Closed", width: 59, formatter: "checkbox",
                        align: "center", firstsortorder: "desc",
                        edittype: "checkbox", editoptions: { value: "Yes:No", defaultValue: "Yes" },
                        stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;true:Yes;false:No" }
                    },
                    {
                        name: "ship_via", label: "Shipped via", width: 87, align: "center", formatter: "select",
                        editoptions: { value: "FE:FedEx;TN:TNT;DH:DHL", defaultValue: "DH" }
                    }
                ],
                datatype: "local",
                data: mydata,
                height: "auto",
                gridview: true,
                rownumbers: true,
                rowNum: 10,
                pager: "#pager",
                sortname: "invdate",
                sortorder: "desc",
                caption: "Usage of columnChooser"
            }).jqGrid("navGrid", "#pager", { add: false, edit: false, del: false }).jqGrid("navButtonAdd", "#pager", {
                caption: "",
                buttonicon: "ui-icon-calculator",
                title: "Choose columns",
                onClickButton: function () {
                    $(this).jqGrid("columnChooser");
                }
            });
    });
</script>

enter image description here

1 个答案:

答案 0 :(得分:1)

我想您忘记在文件中加入一个:ui.multiselect.min.cssjquery-ui.min.jsui.multiselect.min.js(或ui.multiselect.cssjquery-ui.js,{{1} })。文件ui.multiselect.js可以在jqGrid的ui.multiselect.*文件夹中找到。这些文件在CDN上作为免费jqGrid:

的一部分提供
plugins

您也可以更安全的形式包含文件:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.1/plugins/ui.multiselect.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.1/plugins/ui.multiselect.min.js"></script>

文件将被快速加载(如果客户端的Web浏览器支持,则使用HTTP / 2),并且在Web浏览器中将有很好的缓存。

相关问题