This project is read-only.
1
Vote

Sorting columns not working as expected

description

Web page is rendered using Grid MVC with columns/titles set as sortable

user action: click on a column title
  • the expectation is: Grid MVC will handle the sorting and refresh the grid in new sort order
  • actual results: action method called. The reason for this is because a url is built at t the time of column.HeaderRenderer.Render(column) causing the action to be executed and page refreshed per the action
  • How can the desired expectation be meet

comments

oconnef wrote Mar 4, 2016 at 11:35 PM

I was able to get around this issue using a jQuery snippet:

FORCES the page to POST vs GET.

@section Scripts {
<script type="text/javascript">
  $(function(){
      $(".grid-header-title").click(function (e) {
          if ($(e.target).is("a")) {
              // It was the anchor element that was clicked -- meaning, its sortable
              e.preventDefault();

              // '/Search' should be replaced with your form action
              $(document.forms[0]).attr("action", '/Search' + $(e.target).attr("href")); 
              $(document.forms[0]).submit();
          }
    });
  });
</script>
}

oconnef wrote Mar 4, 2016 at 11:39 PM

Apologies, in my excitement, I forgot to note code block
@section Scripts {
<script type="text/javascript">
  $(function(){
      $(".grid-header-title").click(function (e) {
          if ($(e.target).is("a")) {
              // It was the anchor element that was clicked -- meaning, its sortable
              e.preventDefault();

              // '/Search' should be replaced with your form action
              $(document.forms[0]).attr("action", '/Search' + $(e.target).attr("href")); 
              $(document.forms[0]).submit();
          }
    });
  });
</script>
}

sdahl wrote Jul 24, 2016 at 12:43 AM

The javascript above didn't work for me. I was able to handle it in the controller method.
            // if sorting caused this edit, return them to the list view.
            if (Request.Url.ToString().Contains("grid-column"))
            {
                return View("ViewName", Business.GetViewModel());
            }