当前位置: 代码迷 >> JavaScript >> ShieldUI网格:如何获取触发双击的行
  详细解决方案

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

热度:35   发布时间:2023-06-08 09:22:00.0

我有一个搜索掩码,我希望当双击某行时,返回所选行的代码。 我正在使用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变量也为空...

谢谢。

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

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

  相关解决方案