function Rating () {
$(".ratting-item :input").each(function (e) {
var id = this.id;
var IdValue = this.value.trim();
RatingPoint = id.substr(id.length - 1, 1);
if (IdValue == RatingPoint) {
$(this).prop('checked', true);
}
});
$('.ratting-item').rating(function (vote, event) {
var anchor = $(event.currentTarget),
pid = anchor.closest(".ratting-item").data("pid"),
url = $('#ratingURL').val();
var Module = $('#FormType').val();
var ModuleId = pid.substr(0, pid.length - 2);
var RatingId = pid.substr(pid.length - 1, 1);
// show message while doing the database round trip
$('.ratting-item[data-pid=' + pid + ']')
.next()
.text("Placing your vote...");
$.ajax({
url: url,
type: "GET",
data: { rate: vote, id: RatingId, Module: Module, ModuleId: ModuleId },
success: function (data) {
if (data.success) {
//// all went well, here you can say Thank you
$('.ratting-item[data-pid=' + pid + ']')
.next()
.text("Successfully Rated...");
//alert("Successfully Rated...");
}
else {
// There must be an Exception error, let's show it
$('.ratting-item[data-pid=' + pid + ']')
.next()
.text("Something went wrong...");
//alert("Something went wrong...");
}
},
error: function (err) {
// the call thrown an error
$('.result').text(err);
},
complete: function () {
//$(".loading").hide();
}
});
});
}
* i am using template field for rating column The original Form coding is as follows
<script type="text/x-jsrender" id="RatingTemplate">
<div class="ratting-item" data-pid="{{:Id}}_{{:Ratings.Id}}">
<input class="rating" name="vote" type="checkbox" value="1" id="{{:Id}}_rd1_{{:Ratings.RatePoint}}" />
<input class="rating" name="vote" type="checkbox" value="2" id="{{:Id}}_rd2_{{:Ratings.RatePoint}}" />
<input class="rating" name="vote" type="checkbox" value="3" id="{{:Id}}_rd3_{{:Ratings.RatePoint}}" />
<input class="rating" name="vote" type="checkbox" value="4" id="{{:Id}}_rd4_{{:Ratings.RatePoint}}"/>
<input class="rating" name="vote" type="checkbox" value="5" id="{{:Id}}_rd5_{{:Ratings.RatePoint}}"/>
</div>
<span class="result"></span>
@* <div class="col-lg-12">
@Html.Partial("_RatingList", new ViewDataDictionary { { "Ratings", ViewBag.Ratings }, { "CustomerId", "{{:Id}}" } })
</div>*@
</script>
<div class="wrapper wrapper-content animated fadeInRight gridPadding-top">
<div class="row">
<div class="col-lg-12 gridPadding">
<div class="ibox float-e-margins">
<div class="ibox-content ibox-content-border gridPadding">
@(Html.EJ().Grid<CRM.ViewModel.OpportunityVM>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.OpportunityList)
.AllowSorting()
.AllowPaging().PageSettings(p => { p.PageSize(15); })
.ShowColumnChooser()
.AllowFiltering()
.FilterSettings(filter => { filter.FilterType(FilterType.Menu); })
.AllowSearching()
.AllowSelection()
.ToolbarSettings(toolBar => toolBar.ShowToolbar(true).ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
//items.AddTool(ToolBarItems.Edit);
// items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.WordExport);
items.AddTool(ToolBarItems.PdfExport);
items.AddTool(ToolBarItems.PrintGrid);
}))
.Columns(col =>
{
col.Field("Id").Visible(false).HeaderText("Id").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(10).Add();
col.HeaderText("Rating").Template(true).TemplateID("#RatingTemplate").TextAlign(TextAlign.Center).Width(70).Add();
col.Field("Title").HeaderText("Title").TextAlign(TextAlign.Left).Width(100).Add();
col.Field("EstimatedDate").HeaderText("Date").TextAlign(TextAlign.Left).Format("{0:dd-MMM-yy}").Width(50).Add();
col.Field("CustomerName").HeaderText("Customer").TextAlign(TextAlign.Left).Width(95).Add();
col.Field("ProductGroupName").HeaderText("Product Group").TextAlign(TextAlign.Left).Width(70).Add();
col.Field("EstimatedValue").HeaderText("Estimated Value").TextAlign(TextAlign.Right).Width(70).Add();
col.Field("OwnerName").HeaderText("Owner").TextAlign(TextAlign.Left).Width(60).Add();
col.Field("StatusName").HeaderText("Status").TextAlign(TextAlign.Left).Width(40).Add();
col.Field("Ratings.RatePoint").Visible(false).HeaderText("RatePoint").TextAlign(TextAlign.Left).Add();
}))
</div>
</div>
</div>
</div>
</div>
<input type="hidden" value="@ViewBag.Type" id="FormType" />
<input type='hidden' value='@Url.Action("RateModule", "General")' id="ratingURL" />
<script>
$(document).ready(function (event) {
var FormType = '@ViewBag.Type';
$("#FlatGrid_add").click(function (e) {
// alert("dddddddddd")
window.location.rel='nofollow' href = './Create/' + 0 + '?Type=' + FormType;
});
$("#FlatGrid").ejGrid({
recordDoubleClick: function (args) {
var Id = args.data.Id;
window.location.rel='nofollow' href = './Details/' + Id + '?Type=' + FormType;
}
});
});
</script>
<script>
$(function () {
Rating();
$('.e-filter').click(function () {
Rating();
});
$(".e-link").on('click', function (e) {
e.preventDefault();
Rating();
});
});
</script>