José Francisco
José Francisco

Reputation: 304

JQUERY button return to index element

My problem is this, I have a page where there is a button used to change the state of a table. What is happening is that if the page is scrolled and I click the button that is below, it will update the status page and will rise. What I want is that when the state changed it remains the place where the button was clicked.

OPEN SHADOW:

 $(".table-change-link").click(function (e) {
        e.preventDefault();
        var div = this.rel;
        $.get($(this).attr("href"), function (result) {
            $("#" + div).html(result);
            $("#" + div).dialog({ width: 500, height: 200, modal: true });
        });
    });

VIEW:

<td class="table-comand">
        <a href="@Url.Action("AlterarSituacao", ViewBag.Routes)" title="Atualizar Situação"      class="table-change-link" id="situacao" rel="DivAtualizaSituacao"></a>
        <div id="DivAtualizaSituacao"></div>
    </td>

CONTROLLER: this is a action of request

  public ActionResult AlterarSituacao(int page=1)
        {
            CreateRouteValuesForFilters();
            routes.Add("page", page);
            ViewBag.Routes = routes;

            ViewBag.IdSituacaoDocumentoLOV = new SelectList(this.repository.GetAllSituacao().ToList(), "IdSituacaoDocumento", "NomeSituacao");
            return View();
        }

        [HttpPost]
        public ActionResult AlterarSituacao(int IdSituacaoDocumento, int id, int page = 1)
        {
            CreateRouteValuesForFilters();
            routes.Add("page", page);
            ViewBag.Routes = routes;

            this.repository.AlteraSituacaoDocumento(id, IdSituacaoDocumento);
            this.repository.SaveChanges();


            return RedirectToAction("Index",routes);
        }

How make this?

Upvotes: 1

Views: 101

Answers (1)

jim tollan
jim tollan

Reputation: 22483

i think you'll need to add a little more code to show what the jquery does on returning from the AlterarSituacao action. my guess is that after the ajax call, it returns a partialview and pre-pends the updated <td> element and removes the old one- as i said, guesswork until more code present

[update] to show scrolling to bring <td> into view based on id:

$('html, body').animate({
    scrollTop: $('#item.IdSolicitacao').offset().top,
    scrollLeft: $('#item.IdSolicitacao').offset().left
}, 'slow');

obviously, you should be able to grab the <td> id as a variable from your routine, rather than the hardcoded example above.

Upvotes: 1

Related Questions