TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
albert albert
NA
524
0
How to show percentage with Kendo switch with jquery?
Feb 12 2018 1:42 AM
I have a kendo NumericTextBox like this
[code]
I have a kendo NumericTextBox like
this
class
=
"col-sm-2 form-group"
>
Tonen vanaf verschil
@(Html.Kendo().NumericTextBox()
.Name(
"SignalThreshold"
)
.Value(0)
.Step(10)
.Min(0)
.Events(e => e.Change(
"FilterThresholdChange"
))
.Format(
"##.00"
)
)
and I have a kendo
switch
, like
this
:
$(
"#euro-switch"
).kendoMobileSwitch({
onLabel:
"%"
,
offLabel:
"€"
,
change: function (e) {
var label = e.sender.value() ? e.sender.options.onLabel : e.sender.options.offLabel.toString();
var grid = $(
"#overzicht-grid"
).data(
"kendoGrid"
);
if
(e.
checked
) {
grid.showColumn(
"VerschilPercentage"
);
grid.hideColumn(
'Verschil'
)
}
else
{
grid.hideColumn(
"VerschilPercentage"
);
grid.showColumn(
"Verschil"
);
}
var inpbox = $(
'#SignalThreshold'
).data(
"kendoNumericTextBox"
);
inpbox.setOptions(
{
round:
true
,
decimals: 0,
});
inpbox.value(inpbox.value());
}
});
So you can toggle between euro and percentage.
YOu can filter
in
the numericTextbox the amount of euro
's you want to see, for example you only want to see amount of euro'
s bigger then 50 euro. YOu
do
this
with
this
method:
function FilterThresholdChange() {
$(
'#overzicht-grid'
).data(
'kendoGrid'
).dataSource.filter({
operator
: function (task) {
var thresholdAmount = $(
"#SignalThreshold"
).data(
"kendoNumericTextBox"
).value();
if
(thresholdAmount == 0) {
return
true
;
}
else
{
return
(task.Verschil >= thresholdAmount || (task.Verschil < 0 && task.Verschil <= thresholdAmount * -1));
}
}
});
}
But now you can
switch
to percentage, but then you will see the incorrect percentages, because you also see the percentages of 14 % or 20 %, but it has to of course bigger then 50 %
in
this
case
.
So how to combine these two? that you will see euro's bigger then a amount and percentages bigger then a percentage?
Thank you
this
is
the model:
public
class
Overzicht
{
[XmlArrayItem(
"Dvb"
)]
public
List Dienstverbanden {
get
;
set
; }
}
public
class
Dienstverband
{
[XmlAttribute(
"Id"
)]
public
int
Id {
get
;
set
; }
public
string
Naam {
get
;
set
; }
public
string
Contractvorm {
get
;
set
; }
[XmlElement(
"Run1"
)]
public
RunGegevens Run1 {
get
;
set
; }
[XmlElement(
"Run2"
)]
public
RunGegevens Run2 {
get
;
set
; }
public
decimal
Verschil
{
get
{
{
return
Run1.Netto - Run2.Netto;
}
}
}
public
decimal
VerschilPercentage
{
get
{
if
(Run1.Netto == 0 && Run2.Netto != 0)
{
return
-100;
}
public
class
Overzicht
{
[XmlArrayItem(
"Dvb"
)]
public
List Dienstverbanden {
get
;
set
; }
}
public
class
Dienstverband
{
[XmlAttribute(
"Id"
)]
public
int
Id {
get
;
set
; }
public
string
Naam {
get
;
set
; }
public
string
Contractvorm {
get
;
set
; }
[XmlElement(
"Run1"
)]
public
RunGegevens Run1 {
get
;
set
; }
[XmlElement(
"Run2"
)]
public
RunGegevens Run2 {
get
;
set
; }
public
decimal
Verschil
{
get
{
{
return
Run1.Netto - Run2.Netto;
}
}
}
public
decimal
VerschilPercentage
{
get
{
if
(Run1.Netto == 0 && Run2.Netto != 0)
{
return
-100;
}
And
this
is
the kendo overzicht-grid:
@(Html.Kendo().Grid()
.Name(
"overzicht-grid"
)
.AutoBind(
false
)
.Columns(columns =>
{
columns.Bound(d => d.Naam).Title(
"Medewerker"
).ClientTemplate(
"${Naam}"
).Width(300)
.Filterable(f =>
{
f.Extra(
false
);
f.Operators(op =>
{
op.ForString(str =>
{
str.Clear().Contains(
"Bevat"
);
});
});
});
columns.Bound(d => d.Contractvorm).Title(
"Contractvorm"
).ClientTemplate(
"${Contractvorm}"
).Width(200).Filterable(ftb => ftb.Multi(
true
)); ;
columns.Bound(d => d.Run1.Netto).Title(
"Periode 1"
).HeaderTemplate(
""
).Filterable(
true
).HtmlAttributes(
new
{ style =
"text-align:right;"
}).Width(220).ClientTemplate(
"# if (Run1.Netto != 0) { # #= kendo.toString(Run1.Netto, 'n2') # # } #"
).HeaderHtmlAttributes(
new
{ style =
"text-align:right;text-align:right;"
});
columns.Bound(d => d.Run2.Netto).Title(
"Periode 2"
).HeaderTemplate(
""
).Filterable(
true
).HtmlAttributes(
new
{ style =
"text-align:right;"
}).Width(220).ClientTemplate(
"# if (Run2.Netto != 0) { # #= kendo.toString(Run2.Netto, 'n2') # # } #"
).HeaderHtmlAttributes(
new
{ style =
"text-align:right;"
});
columns.Bound(d => d.VerschilPercentage).Title(
"Verschil"
).Filterable(
false
).HtmlAttributes(
new
{ style =
"text-align:right;"
, @
class
=
"NettoVergelijkingVerschil"
}).ClientTemplate(
"# if (VerschilPercentage != 0) { # #= kendo.toString(VerschilPercentage, 'n2') # % # } else { # 0 % # } #"
).Width(165).Format(
"{0:P}"
).HeaderHtmlAttributes(
new
{ style =
"text-align:right;"
}).Hidden();
columns.Bound(d => d.Verschil).Filterable(
false
).HtmlAttributes(
new
{ style =
"text-align:right;"
, @
class
=
"NettoVergelijkingVerschil"
}).ClientTemplate(
"# if (Verschil != 0) { # € #= kendo.toString(Verschil, 'n2') # # } else { # € 0,00 # } #"
).Width(165).Format(
"{0: #.00}"
).HeaderHtmlAttributes(
new
{ style =
"text-align:right;"
});
})
.Filterable(f => f.Mode(GridFilterMode.Menu))
.Sortable()
.Events(e => e.DataBound(
"OngridDatabound"
))
.Pageable(pager => pager.PageSizes(
new
List<
object
>
{ 25, 50, 100, 200, 500 }))
.ClientDetailTemplateId(
"overzicht-grid-details"
)
.Excel(e => e.AllPages(
true
))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.ServerOperation(
false
)
.Model(model =>
{
model.Id(d => d.Id);
model.Field(f => f.Naam);
model.Field(f => f.Contractvorm);
model.Field(f => f.Run1.Netto);
model.Field(f => f.Run2.Netto);
})
.Read(r => r.Action(
"GetOverzicht"
,
"NettoVergelijking"
).Data(
"getData"
))
.Sort(d => d.Add(a => a.Verschil).Descending()
)
)
)
So I
try
to combine the filters
this
:
operator
: function (task) {} with
this
:
change: function (e) {}
I
try
it like
this
:
$(
"#euro-switch"
).kendoMobileSwitch({
onLabel:
"%"
,
offLabel:
"€"
,
change: function (e) {
var label = e.sender.value() ? e.sender.options.onLabel : e.sender.options.offLabel.toString();
var grid = $(
"#overzicht-grid"
).data(
"kendoGrid"
);
if
(e.
checked
) {
grid.showColumn(
"VerschilPercentage"
);
grid.hideColumn(
'Verschil'
)
}
else
{
grid.hideColumn(
"VerschilPercentage"
);
grid.showColumn(
"Verschil"
);
}
var inpbox = $(
'#SignalThreshold'
).data(
"kendoNumericTextBox"
);
if
(inpbox == 0) {
return
true
;
}
else
{
return
(e.Verschil >= inpbox);
}
inpbox.setOptions(
{
round:
true
,
decimals: 0,
});
inpbox.value(inpbox.value());
}
});
But I
get
the message: Verschil undefined.
So how I
get
the value: VerschilPercentage?
Thank you
[/code]
and I have a kendo switch, like this:
$(
"#euro-switch"
).kendoMobileSwitch({
onLabel:
"%"
,
offLabel:
"€"
,
change: function (e) {
var label = e.sender.value() ? e.sender.options.onLabel : e.sender.options.offLabel.toString();
var grid = $(
"#overzicht-grid"
).data(
"kendoGrid"
);
if
(e.
checked
) {
grid.showColumn(
"VerschilPercentage"
);
grid.hideColumn(
'Verschil'
)
}
else
{
grid.hideColumn(
"VerschilPercentage"
);
grid.showColumn(
"Verschil"
);
}
var inpbox = $(
'#SignalThreshold'
).data(
"kendoNumericTextBox"
);
inpbox.setOptions(
{
round:
true
,
decimals: 0,
});
inpbox.value(inpbox.value());
}
});
So you can toggle between euro and percentage.
YOu can filter in the numericTextbox the amount of euro's you want to see, for example you only want to see amount of euro's bigger then 50 euro. YOu do this with this method:
function FilterThresholdChange() {
$(
'#overzicht-grid'
).data(
'kendoGrid'
).dataSource.filter({
operator
: function (task) {
var thresholdAmount = $(
"#SignalThreshold"
).data(
"kendoNumericTextBox"
).value();
if
(thresholdAmount == 0) {
return
true
;
}
else
{
return
(task.Verschil >= thresholdAmount || (task.Verschil < 0 && task.Verschil <= thresholdAmount * -1));
}
}
});
}
But now you can switch to percentage, but then you will see the incorrect percentages, because you also see the percentages of 14 % or 20 %, but it has to of course bigger then 50 % in this case.
So how to combine these two? that you will see euro's bigger then a amount and percentages bigger then a percentage?
Thank you
this is the model:
public
class
Overzicht
{
[XmlArrayItem(
"Dvb"
)]
public
List Dienstverbanden {
get
;
set
; }
}
public
class
Dienstverband
{
[XmlAttribute(
"Id"
)]
public
int
Id {
get
;
set
; }
public
string
Naam {
get
;
set
; }
public
string
Contractvorm {
get
;
set
; }
[XmlElement(
"Run1"
)]
public
RunGegevens Run1 {
get
;
set
; }
[XmlElement(
"Run2"
)]
public
RunGegevens Run2 {
get
;
set
; }
public
decimal
Verschil
{
get
{
{
return
Run1.Netto - Run2.Netto;
}
}
}
public
decimal
VerschilPercentage
{
get
{
if
(Run1.Netto == 0 && Run2.Netto != 0)
{
return
-100;
}
return
Run1.Netto == 0 ? 0 : ((Run1.Netto - Run2.Netto) / Run1.Netto) * 100;
}
}
}
public
class
RunGegevens
{
public
decimal
Netto {
get
;
set
; }
public
decimal
Herr {
get
;
set
; }
}
And this is the kendo overzicht-grid:
@(Html.Kendo().Grid()
.Name(
"overzicht-grid"
)
.AutoBind(
false
)
.Columns(columns =>
{
columns.Bound(d => d.Naam).Title(
"Medewerker"
).ClientTemplate(
"${Naam}"
).Width(300)
.Filterable(f =>
{
f.Extra(
false
);
f.Operators(op =>
{
op.ForString(str =>
{
str.Clear().Contains(
"Bevat"
);
});
});
});
columns.Bound(d => d.Contractvorm).Title(
"Contractvorm"
).ClientTemplate(
"${Contractvorm}"
).Width(200).Filterable(ftb => ftb.Multi(
true
)); ;
columns.Bound(d => d.Run1.Netto).Title(
"Periode 1"
).HeaderTemplate("
").Filterable(true).HtmlAttributes(new { style = "
text-align:right;
" }).Width(220).ClientTemplate("
#
if
(Run1.Netto != 0) { # #= kendo.toString(Run1.Netto,
'n2'
) # # } #
").HeaderHtmlAttributes(new { style = "
text-align:right;text-align:right;" });
columns.Bound(d => d.Run2.Netto).Title(
"Periode 2"
).HeaderTemplate("
").Filterable(true).HtmlAttributes(new { style = "
text-align:right;
" }).Width(220).ClientTemplate("
#
if
(Run2.Netto != 0) { # #= kendo.toString(Run2.Netto,
'n2'
) # # } #
").HeaderHtmlAttributes(new { style = "
text-align:right;" });
columns.Bound(d => d.VerschilPercentage).Title(
"Verschil"
).Filterable(
false
).HtmlAttributes(
new
{ style =
"text-align:right;"
, @
class
=
"NettoVergelijkingVerschil"
}).ClientTemplate(
"# if (VerschilPercentage != 0) { # #= kendo.toString(VerschilPercentage, 'n2') # % # } else { # 0 % # } #"
).Width(165).Format(
"{0:P}"
).HeaderHtmlAttributes(
new
{ style =
"text-align:right;"
}).Hidden();
columns.Bound(d => d.Verschil).Filterable(
false
).HtmlAttributes(
new
{ style =
"text-align:right;"
, @
class
=
"NettoVergelijkingVerschil"
}).ClientTemplate(
"# if (Verschil != 0) { # € #= kendo.toString(Verschil, 'n2') # # } else { # € 0,00 # } #"
).Width(165).Format(
"{0: #.00}"
).HeaderHtmlAttributes(
new
{ style =
"text-align:right;"
});
})
.Filterable(f => f.Mode(GridFilterMode.Menu))
.Sortable()
.Events(e => e.DataBound(
"OngridDatabound"
))
.Pageable(pager => pager.PageSizes(
new
List
{ 25, 50, 100, 200, 500 }))
.ClientDetailTemplateId(
"overzicht-grid-details"
)
.Excel(e => e.AllPages(
true
))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.ServerOperation(
false
)
.Model(model =>
{
model.Id(d => d.Id);
model.Field(f => f.Naam);
model.Field(f => f.Contractvorm);
model.Field(f => f.Run1.Netto);
model.Field(f => f.Run2.Netto);
})
.Read(r => r.Action(
"GetOverzicht"
,
"NettoVergelijking"
).Data(
"getData"
))
.Sort(d => d.Add(a => a.Verschil).Descending()
)
)
)
So I try to combine the filters this:
operator: function (task) {} with this:
change: function (e) {}
I try it like this:
$(
"#euro-switch"
).kendoMobileSwitch({
onLabel:
"%"
,
offLabel:
"€"
,
change: function (e) {
var label = e.sender.value() ? e.sender.options.onLabel : e.sender.options.offLabel.toString();
var grid = $(
"#overzicht-grid"
).data(
"kendoGrid"
);
if
(e.
checked
) {
grid.showColumn(
"VerschilPercentage"
);
grid.hideColumn(
'Verschil'
)
}
else
{
grid.hideColumn(
"VerschilPercentage"
);
grid.showColumn(
"Verschil"
);
}
var inpbox = $(
'#SignalThreshold'
).data(
"kendoNumericTextBox"
);
if
(inpbox == 0) {
return
true
;
}
else
{
return
(e.Verschil >= inpbox);
}
inpbox.setOptions(
{
round:
true
,
decimals: 0,
});
inpbox.value(inpbox.value());
}
});
But I get the message: Verschil undefined.
So how I get the value: VerschilPercentage?
Thank you
Reply
Answers (
0
)
For loop in Array
What is pooling in Ado.Net?