EasyUI Forum

General Category => General Discussion => Topic started by: neos on September 01, 2016, 08:42:09 PM



Title: [SOLVED]Find Different value on selected data in datagrid
Post by: neos 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


Title: Re: [ASK]Find Different value on selected data in datagrid
Post by: stworthy 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
}


Title: Re: [ASK]Find Different value on selected data in datagrid
Post by: neos 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


Title: Re: [ASK]Find Different value on selected data in datagrid
Post by: neos on September 13, 2016, 07:46:05 PM
Any Answer ?


Title: Re: [ASK]Find Different value on selected data in datagrid
Post by: neos on September 21, 2016, 06:32:25 PM
Its possible to do this ?


Title: Re: [ASK]Find Different value on selected data in datagrid
Post by: stworthy 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');
}


Title: Re: [ASK]Find Different value on selected data in datagrid
Post by: neos on September 26, 2016, 02:13:26 AM
Thx very much stworthy. This code works.

Thx.. ;D