EasyUI Forum
April 28, 2024, 11:18:59 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED]Find Different value on selected data in datagrid  (Read 9979 times)
neos
Newbie
*
Posts: 31


View Profile
« on: September 01, 2016, 08:42:09 PM »

Dear All,

I have data in datagrid like this

Code:
[Check Button]
+--+----------+------+--------|
|ID|Inv Number|Amount|Currency|
+--+----------+------+--------|
| 1| a001     |   100|   USD  |
| 2| UHDB23   |  2500|   JPY  |
| 3| 56GT5    |   100|   USD  |
+--+----------+------+--------|
After i select all data an click Check Button I want show error warning if inside of data found 2 or more currencies.
How the code ?

Thx,
Regards,
Neos
« Last Edit: September 26, 2016, 02:15:50 AM by neos » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 02, 2016, 06:55:40 PM »

Call 'getSelections' method to get all the selected rows. If the row amount is greater than 1, show your error message.
Code:
var rows = $('#dg').datagrid('getSelections');
if (rows.length > 1){
  // show your error message
}
Logged
neos
Newbie
*
Posts: 31


View Profile
« Reply #2 on: September 08, 2016, 06:30:25 PM »

Thx stworthy for your reply, but i want find the different currency example:

Code:
[Check Button]
+--+----------+------+--------|
|ID|Inv Number|Amount|Currency|
+--+----------+------+--------|
| 1| a001     |   100|   USD  |
| 2| 56GT5    |   100|   USD  |
+--+----------+------+--------|
I select All data then I Click check button show dialog "No Different Currency"

Code:
[Check Button]
+--+----------+------+--------|
|ID|Inv Number|Amount|Currency|
+--+----------+------+--------|
| 1| a001     |   100|   USD  |
| 2| UHDB23   |  2500|   JPY  |
| 3| 56GT5    |   100|   USD  |
+--+----------+------+--------|
I select All data then I Click check button show dialog "Found Different Currency"

Thx,

Regards,

Neos
« Last Edit: September 08, 2016, 10:30:59 PM by neos » Logged
neos
Newbie
*
Posts: 31


View Profile
« Reply #3 on: September 13, 2016, 07:46:05 PM »

Any Answer ?
Logged
neos
Newbie
*
Posts: 31


View Profile
« Reply #4 on: September 21, 2016, 06:32:25 PM »

Its possible to do this ?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: September 21, 2016, 08:21:38 PM »

It's simple to find the count of different values in an array. Please try this code:
Code:
var cc = [];
var rows = $('#dg').datagrid('getSelections');
for(var i=0; i<rows.length; i++){
var currency = rows[i]['currency'];
if ($.inArray(currency, cc) == -1){ // not found
cc.push(currency);
}
}
if (cc.length > 1){
alert('Found Different Currency');
} else {
alert('No Different Currency');
}
Logged
neos
Newbie
*
Posts: 31


View Profile
« Reply #6 on: September 26, 2016, 02:13:26 AM »

Thx very much stworthy. This code works.

Thx.. Grin
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!