This question is locked. New answers and comments are not allowed.
paulo larini
Top achievements
Rank 1
paulo larini
asked on 30 Jun 2011, 07:06 PM
Hello, this issue seems to be recurrent, but I can't found a good answer for that (Index.cshtml).
I have a page with an ajax form for user to enter filter data:
I have also, a partial view:
And finally a controller:
The problems is:
When I post the form, the "gridPesquisa" element is filled with the correct grid and data.
But, when I sort, page.. in the grid, the data is displayed in a new page, without any style.
Any clues?
I have a page with an ajax form for user to enter filter data:
@using (Ajax.BeginForm( "Pesquisar", "Prestador", new AjaxOptions { HttpMethod="POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "gridPesquisa" } )){ <fieldset> ...some fields here.. <input type="submit" value="Pesquisar" /> </fieldset> }I have also, a partial view:
@model System.Data.DataTable@(Html.Telerik().Grid(Model) .DataBinding(dataBinding => dataBinding.Ajax().Select("_Pesquisar", "Prestador")) .Name("gridPesquisa") .DataKeys(keys => keys.Add(c => c["Handle"])) .HtmlAttributes(new { @class = "grid-padrao" }) .Columns(columns => { columns.Template( @<span> @Html.ActionLink(" ", "Details", new { @id = item["Handle"] }, new { @image = "show", @class = "formatacao" }) @Html.ActionLink(" ", "Edit", new { @id = item["Handle"] }, new { @image = "edit", @class = "formatacao" }) @Html.ActionLink(" ", "Delete", new { @id = item["Handle"] }, new { @image = "delete", @class = "formatacao" }) </span> ).Width(76); columns.Bound("Nome").Title("Nome"); columns.Bound("Logradouro").Title("Endereço"); columns.Bound("Bairro").Title("Bairro"); columns.Bound("Telefone").Title("Telefone"); }) .Pageable() .Sortable() )And finally a controller:
public PartialViewResult Pesquisar(PrestadorFiltro filtro = null) { if (filtro == null) filtro = new PrestadorFiltro { Nome = null, Estado = null }; DataSet prestadores = consultaPrestador.PesquisarPrestadorFiltroCompleto( Session["token"].ToString(), filtro.Estado, filtro.Municipio != null ? Int32.Parse(filtro.Municipio) : 0, 0, 0, 0, filtro.Nome, null, 0, 0, null); return PartialView("_GridPesquisa", prestadores.Tables.Count > 0 ? prestadores.Tables[0] : null); } [GridAction] public ActionResult _Pesquisar() { PrestadorFiltro filtro = new PrestadorFiltro { Nome = null, Estado = null }; DataSet prestadores = consultaPrestador.PesquisarPrestadorFiltroCompleto( Session["token"].ToString(), filtro.Estado, filtro.Municipio != null ? Int32.Parse(filtro.Municipio) : 0, 0, 0, 0, filtro.Nome, null, 0, 0, null); return View(new GridModel(prestadores.Tables.Count > 0 ? prestadores.Tables[0] : null)); }The problems is:
When I post the form, the "gridPesquisa" element is filled with the correct grid and data.
But, when I sort, page.. in the grid, the data is displayed in a new page, without any style.
Any clues?
8 Answers, 1 is accepted
0
paulo larini
Top achievements
Rank 1
answered on 30 Jun 2011, 09:48 PM
Appending:
It looks like the problem is the links that was created:
<th class="t-header" scope="col"><a class="t-link" href="/Prestador/Pesquisar?gridPesquisa-orderBy=Nome-asc">Nome</a></th>
here is the generated html table:
It looks like the problem is the links that was created:
<th class="t-header" scope="col"><a class="t-link" href="/Prestador/Pesquisar?gridPesquisa-orderBy=Nome-asc">Nome</a></th>
here is the generated html table:
<div class="t-widget t-grid grid-padrao" id="gridPesquisa"><table cellspacing="0"><colgroup><col style="width:76px"><col><col><col><col></colgroup><thead class="t-grid-header"><tr><th class="t-header" scope="col"> </th><th class="t-header" scope="col"><a class="t-link" href="/Prestador/Pesquisar?gridPesquisa-orderBy=Nome-asc">Nome</a></th><th class="t-header" scope="col"><a class="t-link" href="/Prestador/Pesquisar?gridPesquisa-orderBy=Logradouro-asc">Endereço</a></th><th class="t-header" scope="col"><a class="t-link" href="/Prestador/Pesquisar?gridPesquisa-orderBy=Bairro-asc">Bairro</a></th><th class="t-header t-last-header" scope="col"><a class="t-link" href="/Prestador/Pesquisar?gridPesquisa-orderBy=Telefone-asc">Telefone</a></th></tr></thead><tbody><tr><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>abc</td><td></td><td class="t-last">440032565564</td></tr><tr class="t-alt"><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>NY1</td><td>ZONA SKOL</td><td class="t-last">004499126333</td></tr><tr><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>RUI BARBOSA</td><td>JARDIM ROSINA</td><td class="t-last">4 444444444</td></tr><tr class="t-alt"><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>Av. Tal</td><td>Centro</td><td class="t-last">999999999999</td></tr><tr><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>teste</td><td>centro</td><td class="t-last">465456446546</td></tr><tr class="t-alt"><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>av. paulista</td><td>centro</td><td class="t-last">787979894564</td></tr><tr><td> <span> <a class="formatacao" href="/Prestador/Details/84" image="show"> </a> <a class="formatacao" href="/Prestador/Edit/84" image="edit"> </a> <a class="formatacao" href="/Prestador/Delete/84" image="delete"> </a> </span></td><td>SILVER MAN</td><td>CENTRO</td><td>CENTRO</td><td class="t-last"></td></tr></tbody></table><div class="t-grid-pager t-grid-bottom"><div class="t-status"><a class="t-icon t-refresh" href="/Prestador/Pesquisar">Atualizar</a></div><div class="t-pager t-reset"><a class="t-link t-state-disabled" href="#"><span class="t-icon t-arrow-first">first</span></a><a class="t-link t-state-disabled" href="#"><span class="t-icon t-arrow-prev">prev</span></a><div class="t-numeric"><span class="t-state-active">1</span></div><a class="t-link t-state-disabled" href="#"><span class="t-icon t-arrow-next">next</span></a><a class="t-link t-state-disabled" href="#"><span class="t-icon t-arrow-last">last</span></a></div><div class="t-status-text">Exibindo itens 1 - 7 de 7</div></div></div>0
Hello Paulo Larini,
Atanas Korchev
the Telerik team
This help article would help.
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
paulo larini
Top achievements
Rank 1
answered on 05 Jul 2011, 01:30 PM
Now I have a partial view:
This view render a table with some action images in the first column, to user show, edit, delete.. the row. This images must appear only when the user pass the mouse over the row. So I write a script to add and remove some classes from the "tr" elements:
Ok. When I do a post in my form, it calls an action called "Pesquisar", that returns the partial view and this images works well.
The problem is when I do a sort, page, etc.. in the grid. It calls the action "_Pesquisar" that returns the GridModel, and my scripts does not works anymore.
What I´m doing wrong ?
@model System.Data.DataTable@(Html.Telerik().Grid(Model) .Name("Grid") .DataBinding(dataBinding => dataBinding.Ajax().Select("_Pesquisar", "Prestador")) .HtmlAttributes(new { @class = "grid-padrao" }) .ClientEvents(events => events .OnDataBinding("atualizarCss")) .Columns(columns => { columns.Template( @<span><a href="/carencia/" image="show" class="formatacao"></a> <a href="/carencia/" image="delete" class="formatacao"></a> </span> ).Width(76); columns.Bound("Nome").Title("Nome"); columns.Bound("Logradouro").Title("Logradouro"); }) .Pageable() .Sortable() )This view render a table with some action images in the first column, to user show, edit, delete.. the row. This images must appear only when the user pass the mouse over the row. So I write a script to add and remove some classes from the "tr" elements:
function atualizarCss(){ $("tr").mouseover(function () { if (this.rowIndex > 0) { $(this).addClass("tr-over"); } comandos = $(this).find("td a") for (var i = 0; i < comandos.length; i++) { if (comandos[i].attributes["image"] != null) { if (comandos[i].attributes["image"].value == "show") { $(comandos[i]).addClass("show"); } else if (comandos[i].attributes["image"].value == "edit") { $(comandos[i]).addClass("edit"); } else if (comandos[i].attributes["image"].value == "delete") { $(comandos[i]).addClass("delete"); } else if (comandos[i].attributes["image"].value == "select") { $(comandos[i]).addClass("select"); } } } }); $("tr").mouseout(function(){ if (this.rowIndex > 0) { $(this).removeClass("tr-over"); } $(this).find("td a").removeClass("show edit delete select"); }); $(".estado").change(function () { var municipios = this.attributes["municipio"].nodeValue; $.ajax({ url: "/Municipio/IndexJson", type: "post", data: "{estado:'" + this.value + "'}", contentType: "application/json; charset=utf-8", dataType: "json", error: function (erro) { alert(erro.responseText); }, success: function (lista) { arrayToDropDownList(lista, $("#"+municipios)) } }); }); }Ok. When I do a post in my form, it calls an action called "Pesquisar", that returns the partial view and this images works well.
The problem is when I do a sort, page, etc.. in the grid. It calls the action "_Pesquisar" that returns the GridModel, and my scripts does not works anymore.
What I´m doing wrong ?
0
Hello Paulo Larini,
Atanas Korchev
the Telerik team
We are not sure what may have gone wrong as the pasted code looks ok. Are the required javascript files of the grid registered?
Regards,Atanas Korchev
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
0
Paulo de Tarso
Top achievements
Rank 1
answered on 05 Jul 2011, 06:10 PM
Olá, Paulo.
Percebi que seu idioma é o português.
Voce é de onde?
Abs
Percebi que seu idioma é o português.
Voce é de onde?
Abs
0
paulo larini
Top achievements
Rank 1
answered on 05 Jul 2011, 06:20 PM
Yep, I´m from Brazil too..
I´m really suffering with this grid. It´s is correctly registered. it works, but all other javascripts connected to the "tr" elements of this grid does not works, after a page, sort, reload..
It looks like the java script code was lost after grid operations.
I´m really suffering with this grid. It´s is correctly registered. it works, but all other javascripts connected to the "tr" elements of this grid does not works, after a page, sort, reload..
It looks like the java script code was lost after grid operations.
0
Paulo de Tarso
Top achievements
Rank 1
answered on 05 Jul 2011, 06:52 PM
Paulo, sou de São Paulo.
Gostaria de conversar mais a respeito de Telerik
Entre em contato, por favor
paulo_mussolini@yahoo.com.br
abs
Gostaria de conversar mais a respeito de Telerik
Entre em contato, por favor
paulo_mussolini@yahoo.com.br
abs
0
paulo larini
Top achievements
Rank 1
answered on 06 Jul 2011, 03:46 PM
I realize what´s is wrong here.
1. I need to call my function "atualizarCss" in the client evento .onDataBound
2. I need to include ClientTemplate for my actions.
But I don't understand why is needed this code duplicated in ClientTemplate.
There is a way more DRY to do this ?
1. I need to call my function "atualizarCss" in the client evento .onDataBound
2. I need to include ClientTemplate for my actions.
@(Html.Telerik().Grid(Model) .Name("Grid") .DataBinding(dataBinding => dataBinding.Ajax().Select("_Pesquisar", "Prestador")) .HtmlAttributes(new { @class = "grid-padrao" }) .ClientEvents(events => events .OnDataBound("atualizarCss") ) .Columns(columns => { columns.Template( @<span><a href="/carencia/" image="show" class="formatacao"></a> <a href="/carencia/" image="delete" class="formatacao"></a> </span> ) .ClientTemplate("<span><a href='/carencia/' image='show' class='formatacao'></a>" + "<a href='/carencia/' image='delete' class='formatacao'></a>" + "</span>") .Width(76); columns.Bound("Nome").Title("Nome"); columns.Bound("Logradouro").Title("Logradouro"); }) .Pageable() .Sortable() )But I don't understand why is needed this code duplicated in ClientTemplate.
There is a way more DRY to do this ?