This is a migrated thread and some comments may be shown as answers.

RadGrid: javascript set_dataSource not working

4 Answers 258 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rogelio
Top achievements
Rank 1
Rogelio asked on 05 May 2014, 02:30 PM
Hi

I followed the directions on the sample: http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/insert-update-delete-client/defaultcs.aspx, i am using a asmx web service to retrieve data like in the sample. Unfortunately i can not make the RagGrid shows the new data, the RadGrid only changes the width of the columns every time i press update button and keep the old data:

            var tableView = $find("<%= rgCuentaGastosDetalle.ClientID %>").get_masterTableView();
            tableView.set_dataSource(result);
            tableView.dataBind();

            var grid = $find("<%= rgCuentaGastosDetalle.ClientID %>");
            grid.repaint();

I have reviewed the content of the result var and it contains the new data, and it does not send any error message. I have Telerik controls version 2014.1.403.40 and using framework v4.0.30319 

Any question or comment please let me know. Thank you very much.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 May 2014, 06:35 AM
Hi Rogelio,

Unfortunately I couldn't replicate the issue at my end. Please have a look into the sample project which works fine at my end. Try to replicate the issue in the provided code or please provide a sample code where I can reproduce the issue for further help.

Thanks,
Princy.
0
Rogelio
Top achievements
Rank 1
answered on 06 May 2014, 04:08 PM
Calling webmethod

REAS.Conceptos.GetGridData('REAS', 'GRIDV2', sesCtaGastoAgenteAduanal.toString(), sesAAProveedorID.toString(), strUsuarioREAS.toString(), updateGrid);


Retrieving data web method:

[WebMethod(EnableSession = true)] public List<Registro> Registros(string ConeccionNombre, string Accion, string CtaGastoAgenteAduanal, string ProveedorID, string Usuario)
        {
            SqlConnection SQLConnection;
            string ConectionString;
            ConectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[ConeccionNombre].ToString();

            string Procedimiento = "[as_AgenAduanal]";
            SQLConnection = new SqlConnection(ConectionString);
            SqlCommand cmdCuentaGastos = new SqlCommand();

            cmdCuentaGastos.Connection = SQLConnection;
            cmdCuentaGastos.CommandType = CommandType.StoredProcedure;
            cmdCuentaGastos.CommandText = Procedimiento;
            cmdCuentaGastos.Parameters.Clear();
            cmdCuentaGastos.Parameters.AddWithValue("@ACCION", Accion);
            cmdCuentaGastos.Parameters.AddWithValue("@CtaGastoAgenteAduanal", CtaGastoAgenteAduanal);
            cmdCuentaGastos.Parameters.AddWithValue("@ProveedorID", ProveedorID);
            cmdCuentaGastos.Parameters.AddWithValue("@USER", Usuario);

            SQLConnection.Open();

            List<Registro> r = new List<Registro>();
            SqlDataReader dr = cmdCuentaGastos.ExecuteReader();
            while (dr.Read())
            {
                r.Add(new Registro(dr));
            }

            SQLConnection.Close();
            return r;
        }

 

Changing values and updating Radgrid

function updateGrid(result) {
var CtaGastoAgenteAduanal = document.getElementById(document.getElementById('<%= dvAgenAduanales2.ClientID %>').rows[2].cells[1].children[0].id);
var sesCtaGastoAgenteAduanal = '<%= Session["sesCtaGastoAgenteAduanal"] %>';
var sesAAProveedorID = '<%= Session["sesAAProveedorID"] %>';
var strUsuarioREAS = '<%= Session["strUsuarioREAS"] %>';
var tableView = $find("<%= rgCuentaGastosDetalle.ClientID %>").get_masterTableView();
var newRegistro = registro.create();

newRegistro.CtaGastoAgenteAduanal = CtaGastoAgenteAduanal.innerHTML.trim();
newRegistro.TipoGasto = $telerik.findButton("<%= chkProveedor.ClientID %>").get_checked();
newRegistro.ProveedorId = $telerik.findComboBox("<%= rcbProveedores.ClientID %>").get_value();
newRegistro.ProveedorDesc = $telerik.findComboBox("<%= rcbProveedores.ClientID %>").get_text();
newRegistro.DetallePosicion = $find("<%= lblPosicion.ClientID %>").get_value();
newRegistro.ConceptoID = $telerik.findComboBox("<%= rcbConceptos.ClientID %>").get_value();
newRegistro.ConceptoDesc = $telerik.findComboBox("<%= rcbConceptos.ClientID %>").get_text();
newRegistro.NumFacturaProveedor = $find("<%= rtNumFacturaProveedor.ClientID %>").get_value();
newRegistro.Importe = $find("<%= rtImporte.ClientID %>").get_value();
newRegistro.IVA = $find("<%= rtIVA.ClientID %>").get_value();
newRegistro.ISRRetenido = $find("<%= rtISRRetenido.ClientID %>").get_value();
newRegistro.IVARetenido = $find("<%= rtIVARetenido.ClientID %>").get_value();
newRegistro.IVARetenidoFlete = $find("<%= rtIVARetenidoFlete.ClientID %>").get_value();
newRegistro.Neto = $find("<%= rtNeto.ClientID %>").get_value();

for (var i = 0; i < result["Data"].length; i++) {
var currentRegistro = registro.create();
currentRegistro.CtaGastoAgenteAduanal = result["Data"][i].CtaGastoAgenteAduanal;
currentRegistro.DetallePosicion = result["Data"][i].DetallePosicion;

if (newRegistro.CtaGastoAgenteAduanal == currentRegistro.CtaGastoAgenteAduanal
&& newRegistro.DetallePosicion == currentRegistro.DetallePosicion) {
    result["Data"][i].TipoGasto = newRegistro.TipoGasto;
    result["Data"][i].ProveedorId = newRegistro.ProveedorId;
    result["Data"][i].ProveedorDesc = newRegistro.ProveedorDesc;
    result["Data"][i].ConceptoID = newRegistro.ConceptoID;
    result["Data"][i].ConceptoDesc = newRegistro.ConceptoDesc;
    result["Data"][i].NumFacturaProveedor = newRegistro.NumFacturaProveedor;
    result["Data"][i].Importe = newRegistro.Importe;
    result["Data"][i].IVA = newRegistro.IVA;
    result["Data"][i].ISRRetenido = newRegistro.ISRRetenido;
    result["Data"][i].IVARetenido = newRegistro.IVARetenido;
    result["Data"][i].IVARetenidoFlete = newRegistro.IVARetenidoFlete;
    result["Data"][i].Neto = newRegistro.Neto;
}
}

tableView.set_dataSource(result["Data"]);
tableView.dataBind();

$find("<%= RadAjaxLoadingPanel1.ClientID %>").hide("<%= rgCuentaGastosDetalle.ClientID %>");
}






0
Rogelio
Top achievements
Rank 1
answered on 06 May 2014, 04:10 PM
Registro.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Collections;

namespace REAS
{
    public class Registro
    {
        #region Private fields

        private string _CtaGastoAgenteAduanal;
        private int _DetallePosicion;
        private bool _TipoGasto;
        private int _ProveedorId;
        private string _ProveedorDesc;
        private int _ConceptoID;
        private string _ConceptoDesc;
        private string _NumFacturaProveedor;
        private decimal _Importe;
        private decimal _IVA;
        private decimal _ISRRetenido;
        private decimal _IVARetenido;
        private decimal _IVARetenidoFlete;
        private decimal _Neto;

        #endregion
     
        #region Constructors
 
        public Registro()
        {       
        }
 
        public Registro(SqlDataReader reader)
        {
            _CtaGastoAgenteAduanal = reader["CtaGastoAgenteAduanal"].ToString().Trim();
            _DetallePosicion = Convert.ToInt32(reader["DetallePosicion"]);
            _TipoGasto = Convert.ToBoolean(reader["TipoGasto"].ToString() == "1" ? "true" : "false");
            _ProveedorId = Convert.ToInt32(reader["ProveedorId"]);
            _ProveedorDesc = reader["ProveedorDesc"].ToString().Trim();
            _ConceptoID = Convert.ToInt32(reader["ConceptoID"]);
            _ConceptoDesc = reader["ConceptoDesc"].ToString().Trim();
            _NumFacturaProveedor = reader["NumFacturaProveedor"].ToString().Trim();
            _Importe = Convert.ToDecimal(reader["Importe"]);
            _IVA = Convert.ToDecimal(reader["IVA"]);
            _ISRRetenido = Convert.ToDecimal(reader["ISRRetenido"]);
            _IVARetenido = Convert.ToDecimal(reader["IVARetenido"]);
            _IVARetenidoFlete = Convert.ToDecimal(reader["IVARetenidoFlete"]);
            _Neto = Convert.ToDecimal(reader["Neto"]);
        }
 
        #endregion
     
        #region Public properties

        public string CtaGastoAgenteAduanal
        {
            get
            {
                return this._CtaGastoAgenteAduanal;
            }
            set
            {
                if ((this._CtaGastoAgenteAduanal != value))
                {
                    this._CtaGastoAgenteAduanal = value;
                }
            }
        }

        public int DetallePosicion
        {
            get
            {
                return this._DetallePosicion;
            }
            set
            {
                if ((this._DetallePosicion != value))
                {
                    this._DetallePosicion = value;            
                }
            }
        }

        public bool TipoGasto
        {
            get
            {
                return this._TipoGasto;
            }
            set
            {
                if ((this._TipoGasto != value))
                {
                    this._TipoGasto = value;
                }
            }
        }

        public int ProveedorId
        {
            get
            {
                return this._ProveedorId;
            }
            set
            {
                if ((this._ProveedorId != value))
                {
                    this._ProveedorId = value;
                }
            }
        }

        public string ProveedorDesc
        {
            get
            {
                return this._ProveedorDesc;
            }
            set
            {
                if ((this._ProveedorDesc != value))
                {               
                    this._ProveedorDesc = value;            
                }
            }
        }

        public int ConceptoID
        {
            get
            {
                return this._ConceptoID;
            }
            set
            {
                if ((this._ConceptoID != value))
                {
                    this._ConceptoID = value;            
                }
            }
        }

        public string ConceptoDesc
        {
            get
            {
                return this._ConceptoDesc;
            }
            set
            {
                if ((this._ConceptoDesc != value))
                {
                    this._ConceptoDesc = value;             
                }
            }
        }

        public string NumFacturaProveedor
        {
            get
            {
                return this._NumFacturaProveedor;
            }
            set
            {
                if ((this._NumFacturaProveedor != value))
                {
                    this._NumFacturaProveedor = value;
                }
            }
        }

        public decimal Importe
        {
            get
            {
                return this._Importe;
            }
            set
            {
                if ((this._Importe != value))
                {
                    this._Importe = value;
                }
            }
        }

        public decimal IVA
        {
            get
            {
                return this._IVA;
            }
            set
            {
                if ((this._IVA != value))
                {
                    this._IVA = value;
                }
            }
        }

        public decimal ISRRetenido
        {
            get
            {
                return this._ISRRetenido;
            }
            set
            {
                if ((this._ISRRetenido != value))
                {
                    this._ISRRetenido = value;
                }
            }
        }

        public decimal IVARetenido
        {
            get
            {
                return this._IVARetenido;
            }
            set
            {
                if ((this._IVARetenido != value))
                {
                    this._IVARetenido = value;
                }
            }
        }

        public decimal IVARetenidoFlete
        {
            get
            {
                return this._IVARetenidoFlete;
            }
            set
            {
                if ((this._IVARetenidoFlete != value))
                {
                    this._IVARetenidoFlete = value;
                }
            }
        }

        public decimal Neto
        {
            get
            {
                return this._Neto;
            }
            set
            {
                if ((this._Neto != value))
                {
                    this._Neto = value;
                }
            }
        }

        #endregion
    }
}
0
Antonio Stoilkov
Telerik team
answered on 08 May 2014, 08:13 AM
Hi,

I have observed the provided code and it seems you have not subscribed to the RadGrid OnCommand client-side event which is needed when client-side binding. You could try adding the OnCommand event as shown below and observe if there is any difference.
<ClientEvents OnRowSelected="rgCuentaGastosDetalle_RowSelected" OnCommand="function () {}" />

Regards,
Antonio Stoilkov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Rogelio
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rogelio
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or