Solved

Need to override jqGrid behavior when checking data-val-unique

Posted on 2011-09-21
4
960 Views
Last Modified: 2012-05-12
I have a grid which uses the data-val-unique attribute of jqGrid to ensure that duplicates aren ot allowed. But the way it handle the comparison is killing performance.

Let's say the user sets a barcode value, jqGrid will instruct all other barcodes to compare themselves with the new code. It's loading the error image file for each as it does. The delay grows with each new addition and we are not able to support more than a dozen barcodes, yet we need to support hundreds. So I need to change the default behavior.

I'd like to call a function when there are duplicates, and only then, have jqGrid use the default error handling for duplicates.

I searched my solution for data-val-unique and found that in the file:

jquery.validator-extensions.js

there's a function which starts with:
$.validator.addMethod('unique', function(value, element, param) {

Can I override this function? How? I would not want to add code to a file from jquery.

Also, any suggestions for writing the function so that it only gets called when there are duplicates found?

Thanks.

0
Comment
Question by:newbieweb
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36578130
won't it be better to use associative arrays (just like maps in java) to see if the value already exist or not

var obj = new Array();

obj["1"] = "1";

so later if you want to check if value 1 is already inserted or not, then just check

if (obj["1"] != null && obj["1"] != undefined)
{
  //value already exists
}
0
 

Author Comment

by:newbieweb
ID: 36578150
Yes, that's a good idea. But I do not want to totally override the duplicates checking built into jQuery (at least I dont think I do). I made a related post where I am trying to override the keyup function, where I could do a check as you'd described, but make the function fit into a fluent API, as the keyup function does.

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27321409.html

I can inject the function which then kicks off the jquery validation, the way keyup kicks it off. But searching for dups with every keystroke if killing performance. I'd rather only kick off the jquery validation code once I already know there's a duplicate.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36578157
i have responded to that question by suggesting you to unbind the onkeyup event and report what happens
0
 

Author Closing Comment

by:newbieweb
ID: 36578252
I was thinking the same thing. BUT, interestingly, once I unbinded it, there was no need for my own validation test. Cool.  Thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now