2012-10-15 126 views
2

實現JQGrid 4.3.0,Jquery 1.6.2和JQuery UI 1.8.16我遇到了內聯編輯的問題。當內嵌編輯被激活時,一些元素被分配一個自動完成。當內聯編輯被取消或保存時,自動完成並不總是消失(通過雙擊選擇文本然後點擊刪除,然後點擊退出以退出行編輯)。在編輯模式下不再考慮該行時,將自動完成控件保留在編輯模式下。JQGrid和JQuery自動完成

也許你可以告訴我初始化是否存在問題,或者我是否知道事件發佈後的「afterrestorefunc」,表明這些字段可以返回到它們的「原始」狀態。原始狀態在JQGrid行中顯示爲數據。

我試過的行關閉,一個.remove()和.empty()後去除DOM:

... 
"afterrestorefunc": function(){ 
    $('.ui-autocomplete-input').remove(); } 
... 

但導致其他的問題,比如jqGrid的是無法找到的小區時序列化數據或編輯行,並且需要刷新頁面,而不僅僅是jqgrid,以便能夠再次查看來自該行的數據。

function CreateCustomSearchElement(value, options, selectiontype) { 
... 
      var el; 
      el = document.createElement("input"); 
      ... 
      $(el).autocomplete({ 
       source: function (request, response) { 
        $.ajax({ 
         url: '<%=ResolveUrl("~/Services/AutoCompleteService.asmx/GetAutoCompleteResponse") %>', 
         data: "{ 'prefixText': '" + request.term + "', 'contextKey': '" + options.name + "'}", 
         dataType: "json", 
         type: "POST", 
         contentType: "application/json; charset=utf-8", 
         success: function (data) { 
          response($.map(data.d, function (item) { 
            return { 
             label: Trim(item), 
             value: Trim(item), 
             searchVal: Trim(item) 
            } 

          })) 
         } 
        }); 
       }, 
       select: function (e, item) { 
        //Select is on the event of selection where the value and label have already been determined.       
       }, 
       minLength: 1, 
       change: function (event, ui) { 
        //if the active element was not the search button      
        //...      
       } 
      }).keyup(function (e) { 
       if (e.keyCode == 8 || e.keyCode == 46) { 
        //If the user hits backspace or delete, check the value of the textbox before setting the searchValue     
        //... 
       } 
      }).keydown(function (e) { 
       //if keycode is enter key and there is a value, you need to validate the data through select or change(onblur) 
       if (e.keyCode == '13' && ($(el).val())) { 
        return false; 
       } 
       if (e.keyCode == '220') { return false } 
      }); 
     } 

其它來源:該元素

自動完成功能是在該行的雙擊創建 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing

http://api.jqueryui.com/autocomplete/

更新: 我試着只創建元素聚焦時的自動完成,以及onblur時將其移除。這也沒有解決這個問題。它似乎只需要觸發自動完成下拉菜單。

回答

0

我有一個自定義啓用/禁用功能,然後調用自動完成。這會導致對同一個jqgrid單元的多個引用調用導致衝突。 因此,在我應該打開內聯編輯的行上雙擊事件。根據記錄類型獲取並分析哪些單元需要啓用/禁用。它確定了頁面加載期間由關聯數組可用的字段,該字段序列化爲隱藏字段值。

function tableRowDoubleClick(id, iRow, iCol, e) { 
... 
setCellEditabilityByRecordType(id); 
...  
} 

細胞可編輯性通過以下方式設置:

function setCellEditabilityByRecordType(id) { 
//change some of the fields to read-only 
var grid = $('#mygrid'); 
var i; 
var cm; 
var cellRecordType = grid.jqGrid('getCell', id, 'RecordType') 
//Determine Fields Disabled by evaluation of data from a hidden field. 
var disablefields = eval(pg_FieldDisable[cellRecordType]); 
for (i = 0; i < disablefields.length; i++) { 
cm = grid.jqGrid('getColProp', disablefields[i]); 
cm.editable = false; 
} 
... 
} 
... 

因此,當該行的初始設置反應以被雙點擊時,細胞可編輯設置。然後觸發「CreateCustomSearchElement」。

但是,如果用戶雙擊該行,它會再次觸發雙擊,設置單元格的可編輯性,但對於同一行。因此,這導致多個引用到單元格,在這一點上,我不知道發生了什麼。我所知道的是,我必須將行可編輯性集中到一個函數中,或者如果當前被雙擊的行確實需要再次設置可編輯性,則可以找到讀取方式。

參考 的JavaScript Assocaitive陣列:http://blog.xkoder.com/2008/07/10/javascript-associative-arrays-demystified/