This question is locked. New answers and comments are not allowed.
I need to get a list of all id's on my grid and pass them back to my controller as a comma delimited list:
I have the following function but being a C# ASP.net Newb (20 years of delphi) I have no idea how to do this. I have this function to try and gather my id's it does not work:
function getIdListClean() {
var ids=null;
var grid = $('#Grid').data('tGrid'); //# + the name given to the grid
$(grid.$tbody[0].rows).filter(function() {
//alert ($(this).html());
alert ($(this).html());
if (ids==null) {
alert ('$(this)[0].html() ' + $(this)[0]);
try
{
ids=$(this)[0].html();
}
catch(err)
{
alert (err.description);
}
}
else {
alert ('12');
ids=ids + "," + $(this)[0].html();
}
alert ('13');
return $(this)[0].html();
});
return ids;
}
And the following function that calls it:
$('#exportSelected').click(function () {
var url = '<%= ResolveUrl("~") %>Customers/ExportToExcel/?data='+getIdListClean();
window.location = url;
});
This should be easy and i bet it is once i am showed how.
Jim
The grid:
<div id="thePanel" class="gridSection prepend-1 span-22 last">
<% Html.Telerik().Grid(Model)
.Name("Grid")
.HtmlAttributes(new { @class = "cust_search_grid" })
.ClientEvents(events => events
.OnRowSelect("Grid_onRowSelect")
.OnLoad("Grid_onLoad")
//.OnDataBinding("Grid_onDataBinding")
.OnDataBound("Grid_onDataBound")
.OnEdit("Grid_onEdit")
.OnDelete("Grid_onDelete")
.OnError("Grid_onError")
)
.DataKeys(keys => keys.Add(c => c.Id))
.ToolBar( toolBar => toolBar.Template(() =>
{ %>
<button type="button" id="selectAll">Select All Records</button>
<button type="button" id="deselectAll">Clear Selection</button>
<label class="customer-label" for="Customers-input">Tag selected:</label>
<%// ReSharper disable ConvertToLambdaExpression
Html.Telerik().ComboBox()
.Name("Tags")
.DataBinding(binding =>
binding.Ajax().Select("GetTags", "Customers"))
.ClientEvents(events => events
.OnError("RedirectOnError")
)
.AutoFill(true)
.HtmlAttributes(new { style = "width: 200px" })
.HighlightFirstMatch(true)
.Render();
// ReSharper restore ConvertToLambdaExpression%>
<button type="button" id="tagApply">Apply Tag</button>
<button type="button" id="tagRemove">Remove Tag</button>
<button type="button" id="getAuditAuthReport">Download Audit Authorization</button>
<button type="button" id="uploadReport">Documents</button>
<div style="font-weight: bold;">Selected Customers: <span id="custCount">0</span></div>
<%}))
.Columns(columns =>
{
columns.Template(c =>
{
%><%= c.Statuses %><%
}).ClientTemplate("<#= Statuses #>").Width(200);
columns.Bound(c => c.Id).
ClientTemplate("<input type='checkbox' name='checkedCustomers' class='selectedCustomer' value='<#= Id #>' />")
.Title("")
.Width(35).HtmlAttributes(new { style = "text-align:center" })
.ReadOnly(true).Filterable(false)
.Sortable(false);
columns.Command(commands =>
{
commands.Delete().ButtonType(GridButtonType.Image).HtmlAttributes(new { style = "width: 15px; min-width: 15px;" });
commands.Edit().ButtonType(GridButtonType.Image).HtmlAttributes(new { style = "width: 15px; min-width: 15px;" });
})
.Width(80);
columns.Bound(c => c.CustomerNumber).Width(100);
columns.Bound(c => c.Company).Width(230);
columns.Bound(c => c.ApplicationId).Width(160);
columns.Bound(c => c.DeliveryUtilityAccountNumbers).Width(180);
columns.Bound(c => c.ContactPerson).Width(170);
columns.Bound(c => c.ContactPhoneNumber).Width(220);
columns.Bound(c => c.ServiceZip).Width(140);
columns.Bound(c => c.EmailAddress).Width(170);
columns.Bound(c => c.BusinessCategory).Width(190);
columns.Bound(c => c.Tags).Width(110).ReadOnly(true);
//columns.Bound(c => c.Title).Width(50);
columns.Bound(c => c.AlternatePhoneNumber).Width(230);
columns.Bound(c => c.BillingAddress1).Width(180);
columns.Bound(c => c.BillingAddress2).Width(180);
columns.Bound(c => c.BillingCity).Width(150);
columns.Bound(c => c.BillingState).Width(150);
columns.Bound(c => c.BillingZip).Width(140);
columns.Bound(c => c.ServiceAddress1).Width(190);
columns.Bound(c => c.ServiceAddress2).Width(190);
columns.Bound(c => c.ServiceCity).Width(150);
columns.Bound(c => c.ServiceState).Width(160);
columns.Bound(c => c.AverageEnergyDemand).Width(270);
columns.Bound(c => c.AverageEnergyConsumption).Width(280);
columns.Bound(c => c.SupplyUtilityAccountNumbers).Width(250);
columns.Bound(c => c.AverageEnergyDemandUnit).Width(270);
columns.Bound(c => c.AverageEnergyConsumptionUnit).Width(270);
columns.Bound(c => c.PremiseNumber).Width(160);
columns.Bound(c => c.MeterNumber).Width(160);
columns.Bound(c => c.TarrifType).Width(140);
columns.Bound(c => c.FacilityName).Width(160);
columns.Bound(c => c.RelatedFacebookAccounts).Width(200);
columns.Bound(c => c.RelatedTwitterAccounts).Width(190);
columns.Bound(c => c.BusinessWebsite).Width(170);
columns.Bound(c => c.ProgramParticipation).Width(210);
columns.Bound(c => c.Accepted).ClientTemplate("<#= Accepted?\"<img alt='true' src='" + Url.Content("~/Content/Images/true.jpg") + "' />\":\"\" #>").Width(150);
columns.Bound(c => c.AppId).Hidden(true);
columns.Bound(c => c.FacilityId).Hidden(true);
columns.Bound(c => c.Id).Hidden(true);
})
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("DoSearch", "Customers")
.Delete("DoDelete", "Customers")
.Update("Update", "Customers")
)
.Scrollable(scrolling => scrolling.Height(300))
.Resizable(resizing => resizing.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Sortable()
.Filterable()
.Pageable(paging =>
paging.PageSize(50))
.Selectable()
.Render();
I have the following function but being a C# ASP.net Newb (20 years of delphi) I have no idea how to do this. I have this function to try and gather my id's it does not work:
function getIdListClean() {
var ids=null;
var grid = $('#Grid').data('tGrid'); //# + the name given to the grid
$(grid.$tbody[0].rows).filter(function() {
//alert ($(this).html());
alert ($(this).html());
if (ids==null) {
alert ('$(this)[0].html() ' + $(this)[0]);
try
{
ids=$(this)[0].html();
}
catch(err)
{
alert (err.description);
}
}
else {
alert ('12');
ids=ids + "," + $(this)[0].html();
}
alert ('13');
return $(this)[0].html();
});
return ids;
}
And the following function that calls it:
$('#exportSelected').click(function () {
var url = '<%= ResolveUrl("~") %>Customers/ExportToExcel/?data='+getIdListClean();
window.location = url;
});
This should be easy and i bet it is once i am showed how.
Jim
The grid:
<div id="thePanel" class="gridSection prepend-1 span-22 last">
<% Html.Telerik().Grid(Model)
.Name("Grid")
.HtmlAttributes(new { @class = "cust_search_grid" })
.ClientEvents(events => events
.OnRowSelect("Grid_onRowSelect")
.OnLoad("Grid_onLoad")
//.OnDataBinding("Grid_onDataBinding")
.OnDataBound("Grid_onDataBound")
.OnEdit("Grid_onEdit")
.OnDelete("Grid_onDelete")
.OnError("Grid_onError")
)
.DataKeys(keys => keys.Add(c => c.Id))
.ToolBar( toolBar => toolBar.Template(() =>
{ %>
<button type="button" id="selectAll">Select All Records</button>
<button type="button" id="deselectAll">Clear Selection</button>
<label class="customer-label" for="Customers-input">Tag selected:</label>
<%// ReSharper disable ConvertToLambdaExpression
Html.Telerik().ComboBox()
.Name("Tags")
.DataBinding(binding =>
binding.Ajax().Select("GetTags", "Customers"))
.ClientEvents(events => events
.OnError("RedirectOnError")
)
.AutoFill(true)
.HtmlAttributes(new { style = "width: 200px" })
.HighlightFirstMatch(true)
.Render();
// ReSharper restore ConvertToLambdaExpression%>
<button type="button" id="tagApply">Apply Tag</button>
<button type="button" id="tagRemove">Remove Tag</button>
<button type="button" id="getAuditAuthReport">Download Audit Authorization</button>
<button type="button" id="uploadReport">Documents</button>
<div style="font-weight: bold;">Selected Customers: <span id="custCount">0</span></div>
<%}))
.Columns(columns =>
{
columns.Template(c =>
{
%><%= c.Statuses %><%
}).ClientTemplate("<#= Statuses #>").Width(200);
columns.Bound(c => c.Id).
ClientTemplate("<input type='checkbox' name='checkedCustomers' class='selectedCustomer' value='<#= Id #>' />")
.Title("")
.Width(35).HtmlAttributes(new { style = "text-align:center" })
.ReadOnly(true).Filterable(false)
.Sortable(false);
columns.Command(commands =>
{
commands.Delete().ButtonType(GridButtonType.Image).HtmlAttributes(new { style = "width: 15px; min-width: 15px;" });
commands.Edit().ButtonType(GridButtonType.Image).HtmlAttributes(new { style = "width: 15px; min-width: 15px;" });
})
.Width(80);
columns.Bound(c => c.CustomerNumber).Width(100);
columns.Bound(c => c.Company).Width(230);
columns.Bound(c => c.ApplicationId).Width(160);
columns.Bound(c => c.DeliveryUtilityAccountNumbers).Width(180);
columns.Bound(c => c.ContactPerson).Width(170);
columns.Bound(c => c.ContactPhoneNumber).Width(220);
columns.Bound(c => c.ServiceZip).Width(140);
columns.Bound(c => c.EmailAddress).Width(170);
columns.Bound(c => c.BusinessCategory).Width(190);
columns.Bound(c => c.Tags).Width(110).ReadOnly(true);
//columns.Bound(c => c.Title).Width(50);
columns.Bound(c => c.AlternatePhoneNumber).Width(230);
columns.Bound(c => c.BillingAddress1).Width(180);
columns.Bound(c => c.BillingAddress2).Width(180);
columns.Bound(c => c.BillingCity).Width(150);
columns.Bound(c => c.BillingState).Width(150);
columns.Bound(c => c.BillingZip).Width(140);
columns.Bound(c => c.ServiceAddress1).Width(190);
columns.Bound(c => c.ServiceAddress2).Width(190);
columns.Bound(c => c.ServiceCity).Width(150);
columns.Bound(c => c.ServiceState).Width(160);
columns.Bound(c => c.AverageEnergyDemand).Width(270);
columns.Bound(c => c.AverageEnergyConsumption).Width(280);
columns.Bound(c => c.SupplyUtilityAccountNumbers).Width(250);
columns.Bound(c => c.AverageEnergyDemandUnit).Width(270);
columns.Bound(c => c.AverageEnergyConsumptionUnit).Width(270);
columns.Bound(c => c.PremiseNumber).Width(160);
columns.Bound(c => c.MeterNumber).Width(160);
columns.Bound(c => c.TarrifType).Width(140);
columns.Bound(c => c.FacilityName).Width(160);
columns.Bound(c => c.RelatedFacebookAccounts).Width(200);
columns.Bound(c => c.RelatedTwitterAccounts).Width(190);
columns.Bound(c => c.BusinessWebsite).Width(170);
columns.Bound(c => c.ProgramParticipation).Width(210);
columns.Bound(c => c.Accepted).ClientTemplate("<#= Accepted?\"<img alt='true' src='" + Url.Content("~/Content/Images/true.jpg") + "' />\":\"\" #>").Width(150);
columns.Bound(c => c.AppId).Hidden(true);
columns.Bound(c => c.FacilityId).Hidden(true);
columns.Bound(c => c.Id).Hidden(true);
})
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("DoSearch", "Customers")
.Delete("DoDelete", "Customers")
.Update("Update", "Customers")
)
.Scrollable(scrolling => scrolling.Height(300))
.Resizable(resizing => resizing.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Sortable()
.Filterable()
.Pageable(paging =>
paging.PageSize(50))
.Selectable()
.Render();