Reputation: 178
I need to refresh DevExpress GridView in the ajax success function after an operation. I am using gridName.Refresh()
method but javascript is throwing "udefined is not a function" error. But when I write this method to Google Chrome Console window, it is working fine. What is the problem? In Addition my javascript codes are in the different JavaScript file, not among the html codes.
This is my jquery ajax codes that in the seperated 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()
Upvotes: 3
Views: 3476
Reputation: 396
First of all you should write window.gv_locations
and next make sure a view that contains the js script see this grid (view should contains grid and script). Give me response if it works.
Upvotes: 1