1 Replies - 1371 Views - Last Post: 18 October 2010 - 01:50 PM

#1 alex1243   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-October 10

Design for repetitive Jquery grid code

Posted 18 October 2010 - 01:31 PM

Hello,

I'm trying to use JQuery Grid to create all sorts of tables. I've noticed that the code is pretty much similar for all my tables except the fact that they have different column names, different row formatting and load at different actions.
I'm new at web programming so I need a little help to keep things in order.
Should I repeat the code in every page I need it?
Should I create some sort of template? If so please give me a hint.

Thank you!
Alex

Is This A Good Question/Topic? 0
  • +

Replies To: Design for repetitive Jquery grid code

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5538
  • View blog
  • Posts: 14,541
  • Joined: 18-April 07

Re: Design for repetitive Jquery grid code

Posted 18 October 2010 - 01:50 PM

You should always strive to cut down on repetitive coding wherever possible. This usually means avoiding duplicating it on each page. The idea is that at some future time you (or someone updating your code) will have to go into every page to change it rather than changing it in one spot.

The ideal solution would be for you to take out the jQuery code, put it into its own javascript file and its own function which then you can call from each page, passing in only the parts of the code that changes. For jQuery this is often the id of the container(s) that the jQuery will then act on. Each page will pass in different ids according to the elements on the page, but the jQuery code itself is in one centrally located external javascript file.

Hope you get the idea. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1