DevExpress MVC GridView Update

I need to update DevExpress GridView in ajax success function after operation. I am using the method gridName.Refresh()

, but javascript is throwing "udefined is not a function" error. But when I write this method in google chrome console window, it works fine. What is the problem? In addition, my javascript codes are in a different JavaScript file and not in the html code.

These are my jquery ajax codes which are in a separate javascript file

function sendToMethod(url) {
    $.ajax({
        type: 'GET',
        url: url,
        contentType: 'application/html; charset=utf-8',
        datatype: 'html'
    })
    .success(function (result) {
        onCloseClick();
        gv_locations.UnselectRows();//gv_locations is not defined
        gv_locations.Refresh();//there is the same error here too
    })
    .error(function (result) {

    });
}

      

This is my GridViewPartial.cshtml file

@Html.DevExpress().GridView(g =>
{
    g.Name = "gv_locations";
    g.KeyFieldName = "PublicIP";
    g.SettingsPager.PageSize = 21;
    g.Width = System.Web.UI.WebControls.Unit.Percentage(100);
    g.ClientSideEvents.SelectionChanged = "onGridSelectionChanged";
    g.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;

    g.CommandColumn.Visible = true;
    g.Settings.ShowGroupPanel = true;
    g.CommandColumn.ShowEditButton = true;
    g.CommandColumn.ShowDeleteButton = true;
    g.CommandColumn.ShowSelectCheckbox = true;
    g.SettingsBehavior.AllowFocusedRow = true;
    g.CallbackRouteValues = new { Controller = "Location", Action = "LocationGridViewPartial", id = ViewBag.Type };

    g.SettingsEditing.UpdateRowRouteValues = new { Controller = "Location", Action = "LocationGridViewInlineUpdate" };
    g.SettingsEditing.DeleteRowRouteValues = new { Controller = "Location", Action = "LocationGridViewInlineDelete" };

    g.Columns.Add(column =>
    {
        column.Caption = "Client";
        column.FieldName = "ClientID";
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    });

    g.Columns.Add(column =>
    {
        column.Caption = "IP";
        column.FieldName = "PublicIP";
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    });

    g.Columns.Add("PublicIPName", "Lokasyon Adı");

    g.Columns.Add(column =>
    {
        column.Caption = "Konum Tipi";
        column.FieldName = "SelectedLocationTypeID";
        column.ColumnType = MVCxGridViewColumnType.ComboBox;
        var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
        comboBoxProperties.DataSource = AtomicAdminPanel.Models.External.Location.LocationDataProvider.GetLocationTypes();
        comboBoxProperties.TextField = "SelectedLocationTypeName";
        comboBoxProperties.ValueField = "SelectedLocationTypeID";
    });

    g.Columns.Add(column =>
    {
        column.Caption = "Oluşturan";
        column.FieldName = "CreatedUser";
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    });

    g.Columns.Add(column =>
    {
        column.Caption = "Oluşturma Tarihi";
        column.FieldName = "CreatedDateTime";
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    });

    g.Columns.Add(column =>
    {
        column.Caption = "Değiştiren";
        column.FieldName = "ChangedUser";
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    });

    g.Columns.Add(column =>
    {
        column.Caption = "Değiştime Tarihi";
        column.FieldName = "ChangedDateTime";
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    });

    g.Columns.Add("IsActive", "Aktif", MVCxGridViewColumnType.CheckBox);

    MVCxGridViewColumn col_listType = new MVCxGridViewColumn("LocationListType");
    col_listType.Visible = false;

    if (ViewBag.Id == "Online")
    {
        MVCxGridViewColumn col_online = new MVCxGridViewColumn("IsOnline", "Çevrimiçi", MVCxGridViewColumnType.Image);
        col_online.SetDataItemTemplateContent(c =>
        {
            ViewContext.Writer.Write("<img src='../../Content/Image/statusOnline.png'/>");
        });
        g.Columns.Add(col_online);
    }
}).Bind(Model).GetHtml()

      

+3


source to share


1 answer


First of all, you have to write window.gv_locations

and then make sure that the view containing the js script see in this grid (the view must contain the grid and the script). Give me an answer if it works.



+1


source







All Articles