0

I have created an MVC application that uses webgrids to display data on my views. In my grid's toolbar I have drop downs, text boxes and a search button that call Jquery to perform various actions. For example, if I click the search button, I refresh the grid via Ajax based on a text entry. This all works well until interaction with the webgrid (page or sort) occurs. We noticed that if any ajax calls are made, then the sorting and paging do not work anymore. Also, if I load the page and page or sort first, then none of my JavaScript works. I have been researching this issue, but have not seen any concrete solutions. Does anyone have recommendations for a solution?

tereško
  • 58,060
  • 25
  • 98
  • 150
Hiszorn
  • 23
  • 1
  • 4
  • I would wager to guess that you are attaching your jquery handlers in the document.ready function using something like $("#Sort").click(function(){}); -> when you reload the grid, the jquery handlers are not reattached. Try using something like this $("#Sort").live('click', function(){}); Complete guess since you posted no code. Also recommend you lookup the jquery documentation on the live() handler. – Tommy Jul 24 '12 at 02:46
  • Thank you Tommy, I added handlers to my jquery and that fixed my Javascript functions upon refresh of the grid. I also discovered that the Ajax call has to be a get since paging and sorting use query string parameters. Here is a post that led me to this: http://stackoverflow.com/questions/9903420/paging-sorting-not-working-on-web-grid-used-in-partial-view – Hiszorn Jul 24 '12 at 03:39
  • I moved my comment to an answer below. If my comments helped, please mark as answered :) – Tommy Jul 24 '12 at 05:08

1 Answers1

1

I would wager to guess that you are attaching your jquery handlers in the document.ready function using something like $("#Sort").click(function(){});. When you reload the grid via an AJAX call, the jquery handlers are not reattached since the DOM was not reloaded. Try using something like this $("#Sort").live('click', function(){}); which will attach the handler to any instance of your identifier once it is present on the page.

This is was a complete guess since you posted no code, but this and the post you referenced above (SO post) seems to have fixed your issue.

Community
  • 1
  • 1
Tommy
  • 39,592
  • 10
  • 90
  • 121