1.
if
(selected.length == 0) {
2.
$(
'#fancyButton1, #fancyButton2'
).attr(
'disabled'
,
'disabled'
);
3.
}
else
if
(selected.length > 0) {
4.
$(
'#fancyButton1, #fancyButton2'
).attr(
'disabled'
,
false
);
5.
}
Now, I need to compare the numeric values in a specific field, and if they are all equal, THEN enable the buttons.. can someone provide an example?
11 Answers, 1 is accepted

#: frikkinNumber #
How do I call to that from a function?

Just doing it with jQuery.. but again, if I have this jquery to grab the text:
1.
$(
'#myTable a.frikkinNumericString'
)).text();
How do I indicate it's from the selected row?
Hello Jeff,
You could use the dataItem method of the Grid API to retrieve the model associated with each row. Here is a sample implementation - in the change event I am checking the Freight field of all selected rows.
I wish you a great day!
Regards,Dimiter Madjarov
Telerik

Thanks for the demo, that helped in other ways as well. Here's my problem (one of many, I assure you!) - I need to compare that set of values throughout ALL of the selected rows to each other to determine if they are all the same or not, I'm doing roughly this, assuming the dataItem in question is called 'myFancyNumber':
01.
if
(selected.length > 1){
02.
var
selectedRows = $(
"#myTable"
).data(
"kendoGrid"
).select();
03.
04.
function
allValuesSame() {
05.
for
(
var
i = 0; i < selectedRows.length; i++)
06.
{
07.
if
(
this
[i] !=
this
[0])
08.
return
false
;
09.
}
10.
return
true
;
11.
}
12.
13.
var
myFancyNumber =
this
.dataItem(
this
.select()).myFancyNumber
14.
if
(allValuesSame(myFancyNumber) ===
true
) {
15.
alert(myFancyNumber);
16.
}
17.
18.
}
I don't have it; a) I haven't figured out how to distinguish the selected rows from each other and b) not 100% sure that function is correct. Thoughts?

NOTE: Actually, after posting the previous code, I realized was a non-functional mess; this is my entire 'change:' function:
01.
change:
function
(e) {
02.
var
selectedRows =
this
.select();
03.
var
selectedDataItems = [];
04.
for
(
var
i = 0; i < selectedRows.length; i++) {
05.
var
dataItem =
this
.dataItem(selectedRows[i]);
06.
selectedDataItems.push(dataItem);
07.
}
08.
09.
var
selected = $.map(
this
.select(),
function
(item) {
10.
return
$(item).text();
11.
});
12.
13.
function
allValuesSame() {
14.
for
(
var
i = 1; i < selectedRows.length; i++)
15.
{
16.
if
(
this
[i] !=
this
[0])
17.
return
false
;
18.
}
19.
return
true
;
20.
}
21.
22.
if
(selected.length > 1){
23.
var
selectedRows = $(
"#myTable"
).data(
"kendoGrid"
).select();
24.
var
fancyNumberText =
this
.dataItem(
this
.select()).fancyNumber
25.
if
(allValuesSame(fancyNumberText) ===
true
) {
26.
alert(fancyNumberText);
//just testing to see what I get
27.
}
28.
return
allValuesSame(fancyNumberText);
29.
}
30.
31.
if
(selected.length == 0) {
32.
$(
'#fancyButton'
).attr(
'disabled'
,
'disabled'
);
33.
}
else
if
(selected.length == 1) {
34.
$(
'#fancyButton'
).attr(
'disabled'
,
false
);
35.
}
else
if
(selected.length > 1 && allValuesSame ==
true
) {
36.
$(
'#fancyButton'
).attr(
'disabled'
,
false
);
37.
}
Again, a) I haven't figured out how to distinguish the selected rows from each other and b) not 100% sure that function is correct. Thoughts?

01.
change:
function
(e) {
02.
var
selectedRows =
this
.select();
03.
var
selectedDataItems = [];
04.
for
(
var
i = 0; i < selectedRows.length; i++) {
05.
var
dataItem =
this
.dataItem(selectedRows[i]);
06.
selectedDataItems.push(dataItem);
07.
}
08.
09.
var
selected = $.map(
this
.select(),
function
(item) {
10.
return
$(item).text();
11.
});
12.
13.
function
allValuesSame() {
14.
for
(
var
i = 1; i < selectedRows.length; i++)
15.
{
16.
if
(
this
[i] !=
this
[0])
17.
return
false
;
18.
}
19.
return
true
;
20.
}
21.
22.
if
(selected.length > 1){
23.
var
selectedRows = $(
"#myTable"
).data(
"kendoGrid"
).select();
24.
var
fancyNumberText =
this
.dataItem(
this
.select()).fancyNumber
25.
if
(allValuesSame(fancyNumberText) ===
true
) {
26.
alert(fancyNumberText);
//just testing to see what I get
27.
}
28.
return
allValuesSame(fancyNumberText);
29.
}
30.
31.
32.
33.
if
(selected.length == 0) {
34.
$(
'#fancyButton'
).attr(
'disabled'
,
'disabled'
);
35.
}
else
if
(selected.length == 1) {
36.
$(
'#fancyButton'
).attr(
'disabled'
,
false
);
37.
}
else
if
(selected.length > 1 && allValuesSame ==
true
) {
38.
$(
'#fancyButton'
).attr(
'disabled'
,
false
);
39.
}
40.
41.
},
Again, I need to compare that set of values throughout ALL of the selected rows to each other to determine if they are all the same or not, I'm doing roughly this, assuming the dataItem in question is called 'myFancyNumber'...
a) I haven't figured out how to distinguish the selected rows from each other and b) not 100% sure that function is correct. Thoughts?
Hello Jeff,
After you have retrieved the dataItems associated to the Grid rows, you could use their ids to distinguish them if this is needed in the current case.
Regards,Dimiter Madjarov
Telerik

After you have retrieved the dataItems associated to the Grid rows, you could use their ids to distinguish them if this is needed in the current case.[/quote]
Great, thanks, can you walk me through how?
Hello Jeff,
The approach for retrieving the id is the same as the one in my first post.
E.g.
selected.each(
function
(){
var
model = grid.dataItem(
this
);
var
id = model.OrderID;
});
Dimiter Madjarov
Telerik

Hello Jeff,
Generally this is a custom logic related to the specific scenario, but for convenience I implemented a sample solution that you could use as a base. Here is the updated example. You could use it as is and modify it further if needed by the current case.
Regards,Dimiter Madjarov
Telerik