ShieldUI网格:如何获取触发双击的行

时间:2019-02-12 17:44:15

标签: javascript datagridview grid shieldui

我有一个搜索掩码,我希望双击某行时,返回所选行的代码。 我正在使用shieldui的shieldGrid。 如何获得选定的行?

我尝试检索选定的行,但它仍然为空。

@using TheBetterWayStoreHandler.Resources
@model TheBetterWayStoreHandler.Models.CustomerGroupModel

@{
    ViewBag.Title = "Ricerca Clienti";
    Layout = "~/Views/Shared/_PagesLayout.cshtml";
}

<form id="searchCustomerForm" action='@Html.Raw(@Url.Action("SearchSelection", "Customer"))?selectedCustomer=' + selectedCustomer.value method="post">
    <nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top" style="background-color: #e3f2fd;">
        <a class="navbar-brand" href="@Url.Action("Index", "Dashboard")">The Better Way - @ViewBag.Title</a>
        <ul class="navbar-nav">
            <li class="nav-item">
                <button type="submit" class="btn btn-outline-success" data-toggle="tooltip" title="Salva" data-placement="bottom" value="Input Button">
                    <span class="fa fa-hdd fa-lg" aria-hidden="true"></span>
                </button>
            </li>
        </ul>
    </nav>
    <div class="container-fluid body-content" style="height: 100%">
        <input id="selectedCustomer" name="selectedCustomer" type="hidden" value="">
        <div id="customerSearchGrid"></div>
    </div>
</form>

<script>
    var selectedCustomerVar = "";
    jQuery(function ($) {
        $("#customerSearchGrid").shieldGrid({
            dataSource: {
                remote: {
                    read: "@Session["ApiPath"]" + "GetCustomerSearch?searchString=" + "@Session["SearchString"]",
                }
            },
            rowHover: true,
            columns: [
                { field: "CustomerCode", width: "80px", title: "@Resources.Tb_CustomerCode", type: String },
                { field: "CustomerDescription", title: "@Resources.Tb_CustomerDescription", type: String }
            ],
            sorting: {
                multiple: true
            },
            scrolling: true,
            height: "700px",
            selection: {
                type: "row",
                multiple: false,
                toggle: true
            },
            editing: {
                enabled: false
            },
            events: {
                selectionChanged: function (e) {
                    var selected = e.target.contentTable.find(".sui-selected");
                    if (selected.length > 0) {
                        selectedCustomer.value = selected[0].cells[0].textContent;
                    }
                    else {
                        selectedCustomer.value = "";
                    }
                },
                ondblClickRow: function(rowId) {
                    var rowData = jQuery(this).getRowData(rowId); 
                    var customerCode = rowData['CustomerCode'];
                    location.href = '@Url.Action("SearchSelection", "Customer")?selectedCustomer=' + customerCode;
                }
            }
        });
    });

$("#customerSearchGrid").dblclick(function () {
    var sel = $("#customerSearchGrid").swidget().selectedRowIndices();
    alert(sel);
    window.searchCustomerForm.submit();
});

selectedCustomer为空,而sel变量也为空...

谢谢。

1 个答案:

答案 0 :(得分:0)

可能在处理选择之前引发了dblclick事件...

您可以尝试使用selectionChanged事件来处理选择更改。