• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Fetch data based on input and without refreshing whole page

 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Find the UI attached.

I have two drop-down boxes and a search button. When clicked on search button, it should fetch data from server and render back the data-grid, which is a simple For-Each loop which iterate over returned data. But I don't want to refresh whole page. And both drop-down boxes should retain their values.

How can I do it? I assume I need to use plain javascript and jQuery. We use both in our project. I can make a server call and fetch the data but how to iterate over it? I can do things like dynamically populating drop down box.

I appreciate step-by-step direction.

Thank you
Untitled.jpg
[Thumbnail for Untitled.jpg]
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jQuery provides Ajax support which allows you to get data in the background without refreshing the whole page. Scroll down on that page to see some examples.

Give it a shot. See what you get stuck on and post that here. For example:
1) Can you write code that alerts the search criteria? (no Ajax needed for this one)
2) Can you write code that sends that search criteria using Ajax and alerts 'success'?
3) Can you write code that sets the new options?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A number of approaches come to mind:

The first two are the basic approaches:

1) Return the pure data (via JSON), and iterate over it in the client, creating the DOM structure of the table from it.

2) If you are already using JSP or some other templating engine on the server, have the response return an already-formatted HTML fragment to inject into the DOM.

A third approach would be the most modern, and a logical extensions of #1 combined with #2:

3) Return the pure data (via JSON), and format it for DOM insertion using a client-side templating engine such as handlebars or mustache.

At this stage of the game, #3 would be my recommended approach.
 
I am displeased. You are no longer allowed to read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic