Need to get a field editable depending on a field content in EXT.NET. Get this.field.msgTarget is null or not an object error

StackOverflow https://stackoverflow.com/questions/8855824

  •  28-10-2019
  •  | 
  •  

Question

I try to use your example to dynamically add/remove editor and get this error: this.field.msgTarget is null or not an object error. I'm new to the ext.net - could somebody help me? Thanks, Jenny

this is my code: EditExample.aspx:

   <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditExample.aspx.cs"        Inherits="myApp.EditExample" %>

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

  <html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
  <title></title>
  <script type="text/javascript">
      var setEditor = function (e) {
         var column = e.grid.getColumnModel().columns[e.column],
         ed = column.getCellEditor(e.row);
         if (ed && (e.value != null || e.value != '')) {
            ed.destroy();
         }
         else {
            column.setEditor(new Ext.form.TextField());
         }
     }
 </script>

 </head>
 <body>
 <form id="form1" runat="server">

 <ext:ResourceManager runat="server" />
 <ext:Store ID="extStore" runat="server" >
 <Reader>
    <ext:JsonReader>
    <Fields>
       <ext:RecordField Name = "Name" />
       <ext:RecordField Name = "Code" ></ext:RecordField>
       <ext:RecordField Name = "Description" ></ext:RecordField>
    </Fields>
    </ext:JsonReader>
 </Reader>
 </ext:Store>
 <div>
 <ext:GridPanel ID="extGrd" runat="server" StripeRows="true" TrackMouseOver="true"
 StoreID="extStore" Cls="x-grid-custom" 

 Height="250px" Layout="fit">
 <ColumnModel ID="cmFC" runat="server"> 
 <Columns>
    <ext:Column ColumnID="Name" DataIndex="Name" Header="Name">
    </ext:Column>
    <ext:Column ColumnID="Code" DataIndex="Code" Header="Code">
    </ext:Column>
    <ext:Column ColumnID="Description" DataIndex="Description" Header="Description"  Editable ="true" >
        <Editor>
        <ext:TextField ID="TextField1" runat="server"></ext:TextField>
        </Editor>
        </ext:Column>
   </Columns> 
</ColumnModel>
<Listeners>
    <BeforeEdit Fn="setEditor" />
    <Render Handler="this.getColumnModel().setEditable(0, true);" />
</Listeners>
<SelectionModel>
   <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true"   MoveEditorOnEnter="true"/>
</SelectionModel> 
<LoadMask ShowMask="true" />
</ext:GridPanel>
</div>

</form>
</body>
</html>

EditExample.aspx.cs

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;

 namespace myApp
 {
     public class info
     {
        public string Name { get; set; }
        public string Code { get; set; }
        public string Description { get; set; }
     }

     public partial class EditExample : System.Web.UI.Page
     {
         protected void Page_Load( object sender, EventArgs e )
         {
            List<info> thisInfo = new List<info>();
            thisInfo.Add( new info { Code = "1", Description = "one", Name = "one Name" } );
            thisInfo.Add( new info { Code = "2", Description = "two", Name = "two Names" } );
            thisInfo.Add( new info { Code = "3", Description = "three", Name = "three Names" } );
            thisInfo.Add( new info { Code = "4", Description = "four", Name = "four Names" } );
            thisInfo.Add( new info { Code = "5", Description = "five", Name = "five Names" } );
            thisInfo.Add( new info { Code = "6", Description = "six", Name = "six Names" } );

            this.extStore.DataSource = thisInfo;
            this.extStore.DataBind();
        }
    }

EDIT: I tried to make the field disabled and readonly. It made the field appear disabled (greyed out), but readable.

  var setEditor = function (e) 
  { 
        var column = e.grid.getColumnModel().columns[e.column], 
                    ed = column.getCellEditor(e.row); 
        if (ed) 
        { 
            if (e.value != null && e.value != '') 
            { 
               ed.readOnly = true; ed.setDisabled(true); 
            } 
            else 
            { 
                ed.readOnly = false; ed.setDisabled(false); 
            } 
        } 
  } 
Was it helpful?

Solution

You can just return false to before event.

var setEditor = function (e) {
          var column = e.grid.getColumnModel().columns[e.column],
          ed = column.getCellEditor(e.row);
          if (ed && (e.value != '')) {
              return false;
          }
      }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top