2

I'm fairly new to the whole JQuery/javascript world, but I've managed to wack together a working jqgrid with a datepicker & custom control (used jquery auto complete) based on code samples i found on the net. I've added the code to a T4 template in my project as it'll probably act as a base/starting point for most pages. (Side note. I'm using asp.net MVC)

JFIDDLE: LINK

1.) I'd like to move the initDateEdit & initDateSearch to the same function (using a parameter, to disable/enable the showOn property) as they are basically similar.

2.) How would be the best way to set nonWorkingDates from outside the new function/file. same applies to the autocomplete_element (I'd like to specify the url)

Changing

"function nonWorkingDates(date)" to => "function nonWorkingDates(date, nonWorkingDates)"

isn't working, (guess it's got got something to do with how its gets called "beforeShowDay: nonWorkingDates")

Thanks in advance!

Rohan Büchner
  • 5,333
  • 4
  • 62
  • 106
  • There are many common way to separate JavaScript code to share it. There are additionally many jqGrid specific ways like setting jqGrid defaults and the usage of column templates. If you want I can explain the features more detailed. Before all you should fix some errors in your code. You should has more as one grid to see what will be common options which can be made defaults. For example the function `afterSubmit` is absolutely wrong. The variables `initDateEdit` and `initDateSearch` assigned to the functions should be defined before the usage. The function `Notify` us undefined and so on. – Oleg Dec 23 '11 at 12:13
  • Please do, any extra help will be greatly appreciated. Some of the functions are undefined in the Jsfiddle link because i didn't copy my exact complete code script, so some functions might be missing, notify can basically be replaced with an alert for demo purposes. thank you :) – Rohan Büchner Jan 05 '12 at 09:36

1 Answers1

1

If you have a chunk of JS code like this:

<script type="text/javascript">
   ... code goes here ...
</script>

You simply copy the whole thing, eliminate the containing script tags, and save the raw code

... code goes here ...

to a file, which you then include with:

<script type="text/javascript" src="yourfile.js"></script>

However, since you're using jquery, you'll have to make sure that this above snippet is placed AFTER the script tag that loads up jquery, or you'll get a "no such function" syntax error.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Thanks! I knew it must have been something else because it didn't make sense that it wouldn't work, I had a look at my code again. The issue was (oh, I'm using MVC as well) don't overlook the obvious i guess :| – Rohan Büchner Dec 23 '11 at 06:45