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

[Solved] Issues with Grid Sorting

3 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Murali
Top achievements
Rank 1
Murali asked on 25 Apr 2011, 06:14 AM
I am using custom ajax binding and am facing probvlems with the grid. I am trying to get the grid in the centre content area of my application sorted. My app has a top menu, side bar and a centre content area.
 The problem is that the call to _CustomBinding method never happens and always calls my DisplayStaticLists method. Even though I have added a workaround for this, I still do not get the desired result.
My controller code is as follows:

public

 

 

ActionResult DisplayStaticLists(string table)

 

 

{

 

 

 

string username = Session["UserName"] as string ?? String.Empty; ;

 

 

 

 

string password = Session["Password"] as string ?? String.Empty; ;

 

 

 

 

int count = -1;

 

 

 

 

// Creating dummy data to bind the grid

 

 

 

var model = MetaqueryService.LoadStaticLists(username, password, table, out count);

 

 

 

 

if (string.IsNullOrEmpty(table)) ViewData["AllSearches"] = "true";

 

 

 

 

else ViewData["AllSearches"] = "false";

 

 

 

 

 

 

if (Request.IsAjaxRequest())

 

 

{

 

 

 

object Data = new

 

{

centerContent =

 

this.RenderPartialViewToString("DisplayStaticLists", model),

 

 

taskpad =

 

String.Empty,

 

 

buttons =

 

String.Empty,

 

 

title =

 

"Static Lists"

 

};

 

 

return Json(Data, JsonRequestBehavior.AllowGet);

 

 

}

 

 

 

else

 

{

 

 

return View ( new GridModel{Data = model});

 

 

}

 

 

 

 

 

 

 

}



[

 

GridAction(EnableCustomBinding = true)]

 

 

 

 

public ActionResult _CustomBinding(GridCommand command, string table)

 

 

{

 

 

 

 

 

string username = Session["UserName"] as string ?? String.Empty; ;

 

 

 

 

string password = Session["Password"] as string ?? String.Empty; ;

 

 

 

 

int count = -1;

 

 

 

 

 

 

var model = MetaqueryService.LoadStaticLists(username, password, table, out count);

 

 

 

 

if (string.IsNullOrEmpty(table)) ViewData["AllSearches"] = "true";

 

 

 

 

else ViewData["AllSearches"] = "false";

 

 

 

 

 

 

//return Json(model, JsonRequestBehavior.AllowGet);

 

 

 

return View(new GridModel { Data = model });

 

 

}



 

 

public static partial class ControllerExtensions

 

{

 

 

public static string RenderPartialViewToString(this ControllerBase controller, string partialPath, object model)

 

 

{

 

 

 

if (string.IsNullOrEmpty(partialPath))

 

 

partialPath = controller.ControllerContext.RouteData.GetRequiredString(

 

"action");

 

 

controller.ViewData.Model = model;

 

 

 

using (StringWriter sw = new StringWriter())

 

 

{

 

 

 

ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, partialPath);

 

 

 

 

ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);

 

 

 

 

// copy model state items to the html helper

 

 

 

foreach (var item in viewContext.Controller.ViewData.ModelState)

 

 

 

 

if (!viewContext.ViewData.ModelState.Keys.Contains(item.Key))

 

 

{

 

viewContext.ViewData.ModelState.Add(item);

 

}

 

 

 

viewResult.View.Render(viewContext, sw);

 

 

 

return sw.GetStringBuilder().ToString();

 

 

}

 

}

 

}



My View Code is as follows:

DisplayStaticLists.cshtml

<

 

 

script type="text/javascript">

 

 

 

function onSelect(e) {

 

 

 

 

var tabstrip = $("#TabStrip").data("tTabStrip");

 

 

 

 

var item = $("li", tabstrip.element)[$("#itemIndex").val()];

 

 

tabstrip.select(item);

 

}

 

 

 

 

 

</script>

 

 

@{

Layout =

 

"";

 

 

}

 

@(Html.Telerik().TabStrip()

 

.Name(

 

"TabStrip")

 

 

.SelectedIndex(1)

 

 

 

.ClientEvents(events => events

 

.OnSelect(

 

"onSelect"))

 

 

.Items(tabs =>

 

{

 

tabs.Add()

 

.Text(

 

"My Static Lists")

 

 

.Content(@<text>

 

@Html.Partial(

 

"MyStaticListGrid")

 

 

</text>);

 

 

 

tabs.Add()

 

.Text(

 

"All Static Lists")

 

 

.Content(@<text>

 

@Html.Partial(

 

"StaticListGrid")

 

 

</text>);

 

 

 

 

 

})

 

)



StaticListGrid.cshtml

 

 

@model

 

IEnumerable<CdcSoftware.Pivotal.ThinClient.Common.ViewBag.StaticListViewModel>

 

 

 

 

 

 

 

 

@{

 

Layout =

 

"";

 

 

}

 

 

 

@(Html.Telerik().Grid(Model)

 

.Name(

 

"Grid")

 

 

.Columns(columns =>

 

{

 

columns.Bound(o => o.Name).Width(120);

 

 

 

if (ViewData["AllSearches"].ToString() != "false") columns.Bound(o => o.ListType);

 

 

columns.Bound(o => o.Permission);

 

columns.Bound(o => o.CreatedByEmployeeName);

 

columns.Bound(o => o.CreateDate);

 

columns.Bound(o => o.EditedByEmployeeName);

 

columns.Bound(o => o.EditDate);

 

})

 

 

 

// .DataBinding(dataBinding => dataBinding.Server().Select("_CustomBinding", "Metaquery"))

 

 

.DataBinding(dataBinding => dataBinding.Ajax().Select(

 

 

"_CustomBinding",

 

 

 

 

"Metaquery"))

 

 

.HtmlAttributes(

 

new { style = "text-align:left" })

 

 

 

 

 

 

//.RowAction(row =>

 

 

 

//{

 

 

 

// row.HtmlAttributes["style"] = "font-weight: normal; font-size:1em; font-family:times;";

 

 

 

//})

 

.Sortable(sorting => sorting

.SortMode(

 

GridSortMode.SingleColumn))

 

 

.Scrollable(scroll => scroll.Height(

 

"385px"))

 

 

.Groupable()

 

.EnableCustomBinding(

 

true)

 

 

 

 

 

 

//.Filterable()

 

)

 



MyStaticListGrid.cshtml

 

 

 

 

@model

 

IEnumerable<CdcSoftware.Pivotal.ThinClient.Common.ViewBag.StaticListViewModel>

 

 

@{

 

Layout =

 

"";

 

 

}

 

 

 

@(Html.Telerik().Grid(Model)

 

 

 

.Name(

 

"Grid")

 

 

.Columns(columns => columns.AutoGenerate(column =>

 

{

 

columns.Bound(o => o.Name).Width(120);

 

 

 

if (ViewData["AllSearches"].ToString() != "false") columns.Bound(o => o.ListType).Width(200);

 

 

}))

 

.DataBinding(dataBinding => dataBinding.Server().Select(

 

"_CustomBinding",

 

 

 

 

"Metaquery"))

 

 

.HtmlAttributes(

 

new { style = "text-align:left"})

 

 

 

 

//.RowAction(row =>

 

 

 

//{

 

 

 

// row.HtmlAttributes["style"] = "font-weight: normal; font-size:1em; font-family:times;";

 

 

 

//})

 

.Sortable()

.Scrollable(scroll => scroll.Height(

 

"385px"))

 

 

.Groupable()

 

.Filterable(filtering => filtering.Filters(filters =>

 

{

 

filters.Add(o => o.Permission).IsEqualTo(

 

"Owner");

 

 

}))

 

)

Please let me what's the issue

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 25 Apr 2011, 07:34 AM
Hi Murali, 

Your grid configuration looks ok. The behavior which you observe may occur of the grid client-side object is not properly initialized. This may occur for two reasons:
  1. There are JavaScript errors
  2. The JavaScript files required by the grid may not be loaded. You can inspect the generated output HTML to verify this.

In any case we could be more helpful if you send us a running sample which reproduces the problem.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Murali
Top achievements
Rank 1
answered on 26 Apr 2011, 08:21 AM
Hi Atanas Korchev,
The problem I am facing is as follows:
The requirement is that on the first call to the controller method DisplayStaticLists, I am returning a json data which is being rendered in the grid which is displayed in the center content area . The other items in the view like navigation and taskpad items are displayed correctly (see screenshot) When I click on one of the column headers to sort the data the following problems occur:
 1) If I use the Ajax binding the call never comes to _CustomBinding method but always comes to DisplayStaticLists . As a work around I added the conditional checks in the DisplayStaticLists method. But the problem is when I return the view, the gird is never displayed in the center content area but is displayed as a seperate page without any navpad / taskpad as required. Also the grid is not properly formatted.(see screen shot - griddisplayoncolumheaderclick.png)
 2) If I try returning Json, a save as dialog is popped up.
3) If I use Server binding, the call does come to _CustomBinding method but the result is same as above.

Please let me know what the issue is
0
Atanas Korchev
Telerik team
answered on 26 Apr 2011, 08:47 AM
Hello Murali,

 I suspect that you are facing this issue. You need to manually register the JavaScript files required by the grid. We also have a code library project showing how to load a grid via ajax inside a tabstrip.

Best wishes,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Murali
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Murali
Top achievements
Rank 1
Share this question
or