Shield ui网格内联编辑在更新行时删除第一个单元格编辑

时间:2018-07-02 15:48:19

标签: shieldui

正如我在标题中提到的那样,一旦我单击“编辑”按钮,就需要为该行的第一个单元格设置可编辑的false。但是,当向表中添加新行(插入表行)时,我不需要应用此方案。我发现实现此目标的最合适方法是通过禁用和启用 ShieldGrid的 events => editinsert函数中的列编辑。

此处显示了到目前为止的方法:

$("#grid1").shieldGrid({
    dataSource: {
        data: products,
        schema: {
            fields: {
                id: { path: "ProductID", type: Number},
                ProductName: { path: "ProductName", type: String },
                quantity: { path: "SupplierID", type: Number },
                price: { path: "UnitPrice", type: Number },
                units: { path: "UnitsInStock", type: Number }
            }
        }
    },
    events: {
        edit: function(e) {
            //disabling here.....
            var first_cell= e.row[0].firstElementChild;  
            alert("Edit event is fired");
        },
        insert: function(e) {
            //enabling here.....
            var first_cell= e.row[0].firstElementChild; 
            alert("Insert event is fired");
        }  
    },
    rowHover: false,
    columns: [
        { field: "ProductName", width: "200px" },
        { field: "quantity" },
        { field: "price" },
        { field: "units" }
    ],
    editing: {
        enabled: true,
        type: "row",  
        confirmation: {
            "delete": {
                enabled: true,
                template: "Delete row {0}?" 
            }
        }
    }
});

通过editorCreating事件,我可以通过以下方式轻松禁用列编辑:

editorCreating: function (e) {
      if (e.field == "columnName") {
            e.options = {enabled: false};
         }

但是该方法不适用于edit事件。 (e.options在插入和编辑函数中调用时在控制台日志中未定义),并且editorCreating也在初始化列编辑器之前被触发,这无法满足我的要求。 :(

console.log(e.row[0].firstElementChild)返回:

td.sui-cell.sui-editable-cell
​
abbr: ""
​
accessKey: ""
​
accessKeyLabel: ""
​
align: ""
​
attributes: NamedNodeMap [ class="sui-cell sui-editable-cell" ]
​
axis: ""
​
baseURI: "http://localhost/.../.../.../2"
​
bgColor: ""
​
cellIndex: 0
​
ch: ""
​
chOff: ""
​
childElementCount: 1
​
childNodes: NodeList [ input.sui-input.sui-input-textbox
 ]
​
children: HTMLCollection { 0: input.sui-input.sui-input-textbox
, length: 1, … }
​
classList: DOMTokenList [ "sui-cell", "sui-editable-cell" ]
​
className: "sui-cell sui-editable-cell"
​
clientHeight: 35
​
clientLeft: 0
​
clientTop: 0
​
clientWidth: 624
​
colSpan: 1
​
contentEditable: "inherit"
​
contextMenu: null
​
dataset: DOMStringMap(0)
​
dir: ""
​
draggable: false
​
firstChild: <input class="sui-input sui-input-textbox" name="ProductName" type="text">
​
firstElementChild: <input class="sui-input sui-input-textbox" name="ProductName" type="text">
​
headers: ""
​
height: ""
​
hidden: false
​
id: ""
​
innerHTML: "<input name=\"ProductName\" class=\"sui-input sui-input-textbox\" type=\"text\">"
​
innerText: ""
​
isConnected: true
​
isContentEditable: false
​
lang: ""
​
lastChild: <input class="sui-input sui-input-textbox" name="ProductName" type="text">
​
lastElementChild: <input class="sui-input sui-input-textbox" name="ProductName" type="text">
​
localName: "td"
​
namespaceURI: "http://www.w3.org/1999/xhtml"
​
nextElementSibling: <td class="sui-cell sui-editable-cell">
​
nextSibling: <td class="sui-cell sui-editable-cell">
​
noWrap: false
​
nodeName: "TD"
​
nodeType: 1
​
nodeValue: null
​
offsetHeight: 36
​
offsetLeft: 0
​
offsetParent: <table class="sui-table">
​
offsetTop: 36
​
offsetWidth: 625
​
onabort: null
​
onanimationcancel: null
​
onanimationend: null
​
onanimationiteration: null
​
onanimationstart: null
​
onauxclick: null
​
onblur: null
​
oncanplay: null
​
oncanplaythrough: null
​
onchange: null
​
onclick: null
​
onclose: null
​
oncontextmenu: null
​
oncopy: null
​
oncut: null
​
ondblclick: null
​
ondrag: null
​
ondragend: null
​
ondragenter: null
​
ondragexit: null
​
ondragleave: null
​
ondragover: null
​
ondragstart: null
​
ondrop: null
​
ondurationchange: null
​
onemptied: null
​
onended: null
​
onerror: null
​
onfocus: null
​
ongotpointercapture: null
​
oninput: null
​
oninvalid: null
​
onkeydown: null
​
onkeypress: null
​
onkeyup: null
​
onload: null
​
onloadeddata: null
​
onloadedmetadata: null
​
onloadend: null
​
onloadstart: null
​
onlostpointercapture: null
​
onmousedown: null
​
onmouseenter: null
​
onmouseleave: null
​
onmousemove: null
​
onmouseout: null
​
onmouseover: null
​
onmouseup: null
​
onmozfullscreenchange: null
​
onmozfullscreenerror: null
​
onpaste: null
​
onpause: null
​
onplay: null
​
onplaying: null
​
onpointercancel: null
​
onpointerdown: null
​
onpointerenter: null
​
onpointerleave: null
​
onpointermove: null
​
onpointerout: null
​
onpointerover: null
​
onpointerup: null
​
onprogress: null
​
onratechange: null
​
onreset: null
​
onresize: null
​
onscroll: null
​
onseeked: null
​
onseeking: null
​
onselect: null
​
onselectstart: null
​
onshow: null
​
onstalled: null
​
onsubmit: null
​
onsuspend: null
​
ontimeupdate: null
​
ontoggle: null
​
ontransitioncancel: null
​
ontransitionend: null
​
ontransitionrun: null
​
ontransitionstart: null
​
onvolumechange: null
​
onwaiting: null
​
onwebkitanimationend: null
​
onwebkitanimationiteration: null
​
onwebkitanimationstart: null
​
onwebkittransitionend: null
​
onwheel: null
​
outerHTML: "<td class=\"sui-cell sui-editable-cell\"><input name=\"ProductName\" class=\"sui-input sui-input-textbox\" type=\"text\"></td>"
​
ownerDocument: HTMLDocument http://localhost/../../../2
​
parentElement: <tr class="sui-alt-row">
​
parentNode: <tr class="sui-alt-row">
​
prefix: null
​
previousElementSibling: null
​
previousSibling: null
​
rowSpan: 1
​
scope: ""
​
scrollHeight: 35
​
scrollLeft: 0
​
scrollLeftMax: 0
​
scrollTop: 0
​
scrollTopMax: 0
​
scrollWidth: 624
​
spellcheck: false
​
style: CSS2Properties(0)
​
tabIndex: -1
​
tagName: "TD"
​
textContent: ""
​
title: ""
​
vAlign: ""
​
width: ""   

但是从那里我找不到禁用列编辑的任何可行解决方案。任何建议都是可取的。

0 个答案:

没有答案