javascript - ShieldUI 网格 : how to get the row where the doubleclick is fired

标签 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 变量也为空...

谢谢。

最佳答案

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

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

关于javascript - ShieldUI 网格 : how to get the row where the doubleclick is fired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54655833/

相关文章:

c# - DataGridView:更改数据源后保留选择?

html - 使最大宽度列流畅?

extjs - 无法在网格中添加过滤器

javascript - 无法阻止点击登录后密码在密码字段中自动延长

javascript - 响应式(Reactive) javascript - 将 ajax 调用转换为带有分页的 Bacon.js 流

javascript - DropzoneJS : upload files and submit form with array of names

c# - 如何使 DataGridView 单元格的字体具有特定颜色?

javascript - 单击按钮执行某些操作,然后单击同一按钮撤消它

c# - 如何让datagridview在离开一行时自动保存记录

jquery - 为动态插入的元素添加css