2010-09-22 80 views
0

你好,我试图设置jqGrid的recreateForm参数为true,以解决使用自定义编辑类型列产生的问题。在这里,我发现最好的形式就是把这条线:jqGrid recreateForm参数

jQuery.extend(jQuery.jgrid.edit, { recreateForm: true }); 

我试过没有成功。任何人都可以帮助我?

的wiew我有问题是代码...

$(document).ready(function() { 
    jQuery("#list").jqGrid({ 
     url: '<%=Url.Action("buildGridData") %>', 
     editurl: '/tipomovi/Edit/', 
     datatype: 'json', 
     mtype: 'GET', 
     colNames: ['Codigo', 'Descripción', 'Tipo Movimiento', 'Inventario Propio', 
        'Tipo Mov. Soporte', 'Clase Bodega Destino'], 
     colModel: [ 
      { name: 'timocodi', index: 'timocodi', key: true, align: 'left', 
       width: 85, editable: true, edittype: 'text', 
       editrules: { required: true, integer: true} }, 
      { name: 'timodesc', index: 'timodesc', align: 'left', width: 300, 
       editable: true, edittype: 'text', editoptions: { maxlength: 40 }, 
       editrules: { required: true} }, 
      { name: 'timosaen', index: 'timosaen', align: 'center', sortable: false, 
       width: 120, editable: true, edittype: 'custom', 
       editoptions: { custom_element: ESElement, custom_value: ESValue }, 
       editrules: { required: true} }, 
      { name: 'timoprop', index: 'timoprop', align: 'center', sortable: false, 
       width: 120, editable: true, edittype: 'checkbox', 
       editoptions: { value: "S:N" }, editrules: { required: true} }, 
      { name: 'timomvso', index: 'timomvso', align: 'center', sortable: false, 
       width: 130, editable: true, edittype: 'text' }, 
      { name: 'clbodesc', index: 'clbodesc', align: 'left', sortable: false, 
       width: 200, editable: true, edittype: 'select', 
       editoptions: { size: 71 }, editrules: { required: true}}], 
     pager: $('#pager'), 
     rowNum: 10, 
     rowList: [10, 20, 30], 
     sortname: 'timocodi', 
     sortorder: 'asc', 
     viewrecords: true, 
     viewsortcols: [true, 'vertical', true], 
     imgpath: '/content/redmond/images', 
     caption: 'Tipos de Movimientos de Inventario', 
     width: 'auto', 
     shrinkToFit: false, 
     height: 'auto', 
     loadComplete: function() { 
      jQuery('#list').setColProp('clbodesc', {editoptions: {value: clases}}); 
     } 
    }); 
    jQuery.extend(jQuery.jgrid.edit, { recreateForm: true });   
}); 

其中

function ESElement(value, options) 
{ 
    //debugger; 
    var v1 = "" 
    var v2 = "" 
    if (value == "E") { 
     v1 = "checked"; 
    } 
    else { 
     v2 = "checked"; 
    } 
    var elemStr = '<div><input type="radio" name="es" id="entrada" value="E" ' + v1 + 
       ' /> Entrada ' + 
       '&nbsp;&nbsp; <input type="radio" name="es" id="salida" value="S" ' + 
       v2 + ' /> Salida </div>'; 
    return $(elemStr)[0]; 
}; 
function ESValue(elem) 
{ 
    rb = elem[0].all[0].checked + ' ' + elem[0].all[1].checked; 
    return rb; 
}; 

奥列格,你好。下面是该视图的完整代码:....

<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
    Tipo de Movimiento 
</asp:Content> 


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

    <h2>Tipo de Movimiento de Materiales</h2> 
    Modo de Edición: 
    <input type="radio" name="rdEditApproach" onclick="inlineEdit();" /> En linea 
    <input type="radio" name="rdEditApproach" onclick="formEdit();" /> Forma<br /><br /> 
    <%=Html.ActionLink("Ir al Menu", "Index", "Menu")%> 
    <table id="list" cellpadding="0" cellspacing="0"></table> 
    <div id="pager" style="text-align:center;"></div> 
<script type="text/javascript"> 
    var clases = $.ajax(
         { url: '/tipomovi/clase/', async: false, 
          success: function(data, result) { 
           if (!result) 
            alert('Fallo recuperacion de clases de Bodega'); 
          } 
         }).responseText; 

    var lastSel; 

    $(document).ready(function() { 
     jQuery("#list").jqGrid({ 
      url: '<%=Url.Action("buildGridData") %>', 
      editurl: '/tipomovi/Edit/', 
      datatype: 'json', 
      mtype: 'GET', 
      colNames: ['Codigo', 'Descripción', 'Tipo Movimiento', 'Inventario Propio', 'Tipo Mov. Soporte', 'Clase Bodega Destino'], 
      colModel: [ 
       { name: 'timocodi', index: 'timocodi', key: true, align: 'left', width: 85, editable: true, edittype: 'text', editrules: { required: true, integer: true} }, 
       { name: 'timodesc', index: 'timodesc', align: 'left', width: 300, editable: true, edittype: 'text', editoptions: { maxlength: 40 }, editrules: { required: true} }, 
       { name: 'timosaen', index: 'timosaen', align: 'center', sortable: false, width: 120, editable: true, edittype: 'custom', 
        editoptions: { custom_element: ESElement, custom_value: ESValue }, editrules: { required: true} 
       }, 
       { name: 'timoprop', index: 'timoprop', align: 'center', sortable: false, width: 120, editable: true, edittype: 'checkbox', editoptions: { value: "S:N" }, editrules: { required: true} }, 
       { name: 'timomvso', index: 'timomvso', align: 'center', sortable: false, width: 130, editable: true, edittype: 'text' }, 
       { name: 'clbodesc', index: 'clbodesc', align: 'left', sortable: false, width: 200, editable: true, edittype: 'select', editoptions: { size: 71 }, editrules: { required: true}}], 
      pager: $('#pager'), 
      rowNum: 10, 
      rowList: [10, 20, 30], 
      sortname: 'timocodi', 
      sortorder: 'asc', 
      viewrecords: true, 
      viewsortcols: [true, 'vertical', true], 
      imgpath: '/content/redmond/images', 
      caption: 'Tipos de Movimientos de Inventario', 
      width: 'auto', 
      shrinkToFit: false, 
      height: 'auto', 
      loadComplete: function() { 
       jQuery('#list').setColProp('clbodesc', { editoptions: { value: clases} }); 
      } 
     }); 
     jQuery.extend(jQuery.jgrid.edit, { recreateForm: true });   
    }); 


    function ESElement(value, options) 
    { 
     //debugger; 
     var v1 = "" 
     var v2 = "" 
     if (value == "E") { 
     v1 = "checked"; 
     } 
     else { 
     v2 = "checked"; 
     } 
     var elemStr = '<div><input type="radio" name="es" id="entrada" value="E" ' + v1 + ' /> Entrada ' + 
        '&nbsp;&nbsp; <input type="radio" name="es" id="salida" value="S" ' + v2 + ' /> Salida </div>'; 
     return $(elemStr)[0]; 
    }; 
    function ESValue(elem) 
    { 
     rb = elem[0].all[0].checked + ' ' + elem[0].all[1].checked; 
     return rb; 
    }; 

    function inlineEdit() { 
     $('input[name=rdEditApproach]').attr('disabled', true); 
     $('#list').navGrid(
       '#pager', 
     //Activando botones 
       {add: true, del: true, edit: false, search: false }, 
     //opciones de adición 
       {width: 'auto', url: '/tipomovi/Create/' }, 
     //delete options 
       {url: '/tipomovi/Delete/' } 
      ); 
     //add onSelectRow event to support inline edit 
     $('#list').setGridParam({ 
      onSelectRow: function(id) { 
       if (id && id != lastSel) { 
        //save changes in row 
        $('#list').saveRow(lastSel, false); 
        lastSel = id; 
       } 
       //trigger inline edit for row 
       $('#list').editRow(id, true); 
      } 
     }); 
    }; 

    function formEdit() { 
     $('input[name=rdEditApproach]').attr('disabled', true); 
     $('#list').navGrid(
      '#pager', 
      //enabling buttons 
      {add: true, del: true, edit: true, search: true}, 
      //edit option 
      {width: 'auto'}, 
      //add options 
      {width: 'auto', url: '/tipomovi/Create/' }, 
      //delete options 
      { url: '/tipomovi/Delete/', 
      width: 'auto', 
      afterSubmit: function(r, d) { 
       return [r.responseText == "", r.responseText];} 
      }, 
      //search options 
      {url: '/tipomovi/buildGridData/', width: 'auto', closeAfterSearch: true } 
      );  
    }; // function FormEdit 


</script> 
</asp:Content> 
+0

我无法在代码中看到任何你使用表单编辑或任何编辑的地方。你如何做到这一点?你真的需要自定义编辑,而不只是自定义格式(请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter)和unformatter(请参阅http://www.trirand.com/jqgridwiki /doku.php?id=wiki:custom_formatter#unformatting)?顺便说一句,你可以随时修改你的问题的文字。如果您可以修改旧的问题,则不需要创建新问题。 – Oleg 2010-09-22 20:43:38

回答

0

你如何写代码部份的风格是因为我做了很多其他的,所以我很难找到确切位置,你有问题。

我看到的唯一明确错误是您在inlineEdit函数中使用了navGrid的错误参数。您应该插入一些{},以定义添加和删除参数。目前,您在'编辑'操作中使用'添加'参数的网址,在'添加'操作中使用Delete。我不确定这是你正在搜索的错误。

我在我的代码做的总是:

  1. 我把从该ASP.NET MVC视图的JavaScript代码清晰的分离。视图帽通常只包含<script>,并引用.js文件。至少99%的代码不在View中。 MVC概念如果自己认为View应该基本上没有代码和逻辑。如果只应查看控制器中准备的数据。此外,Javascript文件是静态文件,并可以很好地缓存在客户端。
  2. 我尝试使用较少的全局变量。在您当前的代码clases,lastSel,ESValueESElement, ESValue,inlineEdit,formEdit都是grobal对象。
  3. 我尽量不要使用类似<input onclick="inlineEdit();" />的结构,因为onclick事件所调用的函数必须是全局的。今天我answerd已经在关于这个问题的问题。而不是'onclick'你可以在$(document).ready(function() {函数的某处代码$("#inlineEdit").click(function(e) {/* the code of inlineEdit */});其中id =“inlineEdit”应该是第一个<input>按钮中的id。
  4. 要告诉信任我看不出有一个单选按钮,它将在第一次单击时被停用,并定义您使用的编辑模式,我个人在最多jqGrids 两种模式启用。您应该做的唯一事情是在窗体编辑的beforeInitData事件hanbler中调用restoreRow(lastSel)。 I suggested将此调用包含在标准的jqGrid代码中。在http://www.ok-soft-gmbh.com/jqGrid/DatePicker.htm你可以看到一个这样做的例子。此外,在大多数网格中,我使用双击进入内联编辑模式(请参阅jqGrid - edit only certain rows for an editable column)。在我看来,网格的滚动更容易查看数据,以防网格显示不仅用于编辑,而且还用于显示数据。

已更新:还有一点小话。你计算$(document).ready之外的值clases这是不好的,你这样做是同步的。您在那里使用valueeditoptions。您应该使用dataUrl。如果需要更改由'/tipomovi/clase/'返回的数据,则可以另外使用buildSelect函数。自从某些版本的jqGrid以来,这种方式已经存在。参数imgpath改为deprecated

+0

Oleg,非常感谢。我非常感谢您的意见。我将尝试应用它们以获得更好的应用程序代码。再次感谢。 – 2010-09-23 02:59:28