This question is locked. New answers and comments are not allowed.
I have a custom toolbar command (for exporting the data), and the implementation is very similar to the example on the telerik demo site. Because I have custom binding and am only returning some of the data to the grid at one time, I need to get the current sorting / filtering state of the grid. Ideally I would like to post a GridCommand to the action, but it keeps just setting the sorting and filtering to size of 0 and setting the pagesize to 10 (mine is 20) and page number to 1. I can post a stringified JSON of the sort descriptor (looks like this): "{"title":"Test Run","member":"TestRunTestCaseXref.TestRun.TestRunName","type":"String","order":"asc"}"....
That works fine when I make the parameter of the controller action a string, but when I make it a SorterGuy (yes, I will change the name), the variable is always null.
For the record, I have multiple grids inside a tabview, and all but one of them are loaded into the tabstrip through ajax calls using an addtab function in a telerik.extensions.js file I found on the internet. It shouldn't matter, but I have had trouble sometimes getting those grids to work like the first one. All my testing is being done on the first grid right now though.
SorterGuy and the controller action look like this:
I have an ajax grid with the following javascript:
My grid code looks like this:
That works fine when I make the parameter of the controller action a string, but when I make it a SorterGuy (yes, I will change the name), the variable is always null.
For the record, I have multiple grids inside a tabview, and all but one of them are loaded into the tabstrip through ajax calls using an addtab function in a telerik.extensions.js file I found on the internet. It shouldn't matter, but I have had trouble sometimes getting those grids to work like the first one. All my testing is being done on the first grid right now though.
SorterGuy and the controller action look like this:
public class SorterGuy{ public string title{get; set;} public string member{get; set;} public string type{get; set;} public string order{get;set;}}[GridAction]public ActionResult ExportToolGrid(SorterGuy aval) //SorterGuy is null unless I make it a string.{ RouteValueDictionary rvd = this.GridRouteValues(); //I only get one key here, pagesize... it is the right value though. foreach (string key in rvd.Keys) { object val = rvd[key]; int i = 0; } MemoryStream output = new MemoryStream(); StreamWriter writer = new StreamWriter(output, Encoding.UTF8); writer.WriteLine(); writer.Flush(); output.Position = 0; return File(output, "text/comma-separated-values", "Orders.csv");}I have an ajax grid with the following javascript:
function onDataBound(){ var data = $('#@((String)ViewData["gridname"])').data('tGrid'); if (data.sorted.length > 0) { // Get the export link as jQuery object var $exportLink = $('#export' + '@((String)ViewData["gridname"])'); // Get its 'href' attribute - the URL where it would navigate to var href = $exportLink.attr('href'); href = href.replace(/aval=(.*)/, 'aval=' + (JSON.stringify(data.sorted[0]) || '~')); // Update the 'href' attribute $exportLink.attr('href', href); }}My grid code looks like this:
@(Html.Telerik().Grid(this.Model == null ? BaseLibrary.TestCaseInstance.LoadAll(null, null, null).Take(Convert.ToInt32(ViewData["pagesize"])) : this.Model).Name((String)ViewData["gridname"]).Columns(columns => { columns.Bound(o => o.ResultName).Title("Result").Width(40); columns.Bound(o => o.TestRunTestCaseXref.TestRun.TestRunName).Title("Test Run").Width(100); columns.Bound(o => o.TestRunTestCaseXref.TestCase.TestCaseName).Title("Test Case").Width(150); columns.Bound(o => o.TestRunTestCaseXref.TestRun.TestTool.TestToolName).Title("Tool").Width(40); columns.Bound(o => o.TestRunTestCaseXref.TestRun.Package.PackageName).Title("Package").Width(40); columns.Bound(o => o.TestRunTestCaseXref.TestRun.TestRunVersion).Title("Version").Width(40); columns.Bound(o => o.RunDateTime).Title("Run Date Time").Width(80); }) .DataBinding(databinding => { databinding.Ajax().Select("GetToolGridData", "UI", new { gridname = (string)ViewData["gridname"] }); }) .EnableCustomBinding(true) .ToolBar(commands => commands .Custom().HtmlAttributes(new { id = "export" + (String)ViewData["gridname"] }) .Text("Export to CSV").Action("ExportToolGrid", "UI", new { aval = "~" }) ) .Resizable(resizing => resizing.Columns(true)) .Scrollable(c => c.Height("450px")) .Sortable() .Pageable(settings => settings.Total((int)ViewData["total"]).PageSize(Convert.ToInt32(ViewData["pagesize"]))) .Filterable() .Footer(true) .ClientEvents(events => events.OnRowDataBound("onRowDataBound").OnDataBound("onDataBound")))