I'm new to bootstrap so I hope that you will be able to help me out. I did some searching on the internet but I can't find a solution that works for me. I want to disable sorting for all of the columns except for the last two which i want to sort in descending order:
#model CCQAS.WebApp.Areas.Credentialing.Models.CredCustodyViewModel
#using CCQAS.API.Model
#{Layout = "~/Areas/Credentialing/Views/Shared/_CredLayout.cshtml";
ViewBag.Title = "Custody History";}
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
#ViewBag.Title
</h3>
</div>
#{if (Model.CredCustodyList.Count > 0)
{
<table class="table table-striped table-bordered" id="myTable">
<thead>
<tr>
<th class="text-center">
UIC
</th>
<th class="text-center">
POC
</th>
<th class="text-center">
#Html.DisplayNameFor(model => model.CredCustodyList[0].DescriptionTxt)
</th>
<th class="text-center">
#Html.DisplayNameFor(model => model.CredCustodyList[0].EffectiveDate)
</th>
<th class="text-center">
#Html.DisplayNameFor(model => model.CredCustodyList[0].EndDateString)
</th>
</tr>
</thead>
#foreach (CredCustody credCustody in Model.CredCustodyList)
{
<tr>
<td>
#credCustody.MTFNameTxt<br />
#credCustody.MTFCity <span> </span>#credCustody.UIC
</td>
<td>
#credCustody.PublicAffairsCoorTxt <br />
<span>Phone: </span> #credCustody.MTFCommPhoneTxt <br />
<span>DSN: </span> #credCustody.MTFDSNPhoneTxt <br />
<span>Fax: </span> #credCustody.MTFFaxPhoneTxt <br />
<span>Email: </span> #credCustody.MTFEmailTxt
</td>
<td>
#credCustody.DescriptionTxt
</td>
<td>
#credCustody.EffectiveDateString
</td>
<td>
#credCustody.EndDateString
</td>
</tr>
}
</table>
}
else
{
<p>
<h3 class="text-center">No Records Found</h3>
</p>
}
}
</div>
</div>
</div>
#section scripts{
<script>
$(document).ready(function () {
initializeDataTableNoPaging();
#*Disables all columns from sorting except for the last two: Effective Date and End Date*#
$('#myTable').tablesorter({
"aoColumns": [
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false },
null,
null
]
});
});
</script>
}
As explained in the documentation from here you need to mark which columns you don't want to be sortable using the headers option.
In your code use:
$('#myTable').tablesorter({
headers: {
0: {
sorter: false
},
1: {
sorter: false
},
2: {
sorter: false
}
}
});
I found a solution. The first thing that I had to do was give a name to my headers:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="text-center">
UIC
</th>
<th class="text-center" id="POC_header">
POC
</th>
<th class="text-center" id="Desc_header">
#Html.DisplayNameFor(model => model.CredCustodyList[0].DescriptionTxt)
</th>
<th class="text-center" id="Effective_header">
#Html.DisplayNameFor(model => model.CredCustodyList[0].EffectiveDate)
</th>
<th class="text-center">
#Html.DisplayNameFor(model => model.CredCustodyList[0].EndDateString)
</th>
</tr>
</thead>
Second, I added this code to disable the sorting:
#section scripts{
<script>
$(document).ready(function () {
initializeDataTableNoPaging();
#*Disables all columns from sorting except for the last two: Effective Date and End Date*#
$("#POC_header").off('click'); //disables click event
$("#POC_header").addClass("sorting_disabled");
$("#POC_header").removeClass("sorting_asc");
$("#Desc_header").off('click'); //disables click event
$("#Desc_header").addClass("sorting_disabled");
$("#Desc_header").removeClass("sorting"); //needed to remove the sorting class to get rid of the sorting arrows on header
$("#Desc_header").removeClass("sorting_asc");
$("#Effective_header").addClass("sorting_desc");
$("#Effective_header").removeClass("sorting_asc"); //Sorts effective date in descending order
});
</script>
}
Related
<div class="col-md-5">
<div class="card border-0 shadow">
<div class="card-body ">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.Barangay)
</th>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.Confirmed)
</th>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.PUI)
</th>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.PUM)
</th>
<th></th>
</tr>
</thead>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Barangay)
</td>
<td style="text-align:center;">
#Html.DisplayFor(modelItem => item.Confirmed)
</td>
<td style="text-align:center;">
#Html.DisplayFor(modelItem => item.PUI)
</td>
<td style="text-align:center;">
#Html.DisplayFor(modelItem => item.PUM)
</td>
</tr>
}
</table>
</div>
</div>
</div>
</div>
I can't remove it although I tried using different styles of table.
Sorry for this dumb question for I am new to web development and ASP.Net MVC.
Please see image below for reference.
Thanks in advance for any help.
https://i.stack.imgur.com/LosFA.png
This is because you have an extra th tag in your code:
<th style="text-align:center;">
Html.DisplayNameFor(model => model.PUM)
</th>
<th></th> <!------------------delete this->
if your table have 5 head table columns and your table body have 4, the body expect 1 column and keeps the space
I have those 2 columns and I want to put the row where's the travel consultant = Username1 with green color on the letters and username2 with red color on the letters.
How can I do this ?
<table class="table table-striped table-hover table-bordered tablesModel">
<thead>
<tr>
<th data-field="#Html.DisplayNameFor(model => model.Travel_Consultant)" data-sortable="true">
#Html.DisplayNameFor(model => model.Travel_Consultant)
</th>
#*scope1, scope2*#
<th data-field="#Html.DisplayNameFor(model => model.Description)">
#Html.DisplayNameFor(model => model.Description)
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td data-field="#Html.DisplayNameFor(model => model.Travel_Consultant)" data-sortable="true">
#Html.DisplayFor(modelItem => item.Travel_Consultant)
</td>
<td data-field="#Html.DisplayNameFor(model => model.Description)">
#Html.DisplayFor(modelItem => item.Description)
</td>
<td style="text-align:center;">
<button onclick="createOrEdit(#item.ExtraJobsID)" type="button" class="btn-xs buttongreenpt">
<i class="fa fa-edit fa-20px"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
If you want to apply code inside your view, try something like this inside your #foreach:
<tr>
#if (model.Travel_Consultant == "Username1")
{
<td data-field="#Html.DisplayNameFor(model => model.Travel_Consultant)"
data-sortable="true" style="color: red">
#Html.DisplayFor(modelItem => item.Travel_Consultant, new { #style =
"color:green;" })
</td>
}
else if(model.Travel_Consultant == "username2")
{
<td data-field="#Html.DisplayNameFor(model => model.Description)">
#Html.DisplayFor(modelItem => item.Description, new { #style =
"color:red;" })
</td>
}
<td style="text-align:center;">
<button onclick="createOrEdit(#item.ExtraJobsID)" type="button" class="btn-xs buttongreenpt">
<i class="fa fa-edit fa-20px"></i>
</button>
</td>
</tr>
In foreach loop
if(consultant = Username1)
assign class Green to that row
.Green{color: green;}
else if(consultant = Username1)
assign class Red to that row
.Red{color: red;}
Hope this will solve your problem.
I have a list of orders in a gridview with customer html which has paging using PagedList asp.net mvc. I have a checkbox for each order in the list. When I use "Check all" to check all orders it should keep the checkbox checked when I go to page 2-3-4. But I lose the checked status when I move to next page. Can anyone help please?
JavaScript code :
$(document).ready(
function () {
$('#selectAll').click(
function () {
$('#TabOrdre td input:checkbox').prop('checked', $(this).is(':checked'));
if ($(this).is(':checked')) {
$('#TabOrdre td input:checkbox').each(function () {
if ($.inArray($(this).val(), list) === -1)
list.push($(this).val());
});
getAll = true;
}
else {
list = [];
getAll = false;
}
}
);
View code :
<section class="panel panel-default">
<header class="panel-heading m-b-none">Liste des ordres</header>
<div class="row wrapper">
<div class="col-md-12 space20">
<div class="doc-buttons">
<a class="btn btn-s-md btn-warning ajout-container"> <i class="fa fa-plus"></i> Ajouter un ordre </a>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped b-t b-light">
<thead>
<tr>
<th width="20">
<input type="checkbox" id="selectAll" value="-1">
</th>
<th style="white-space:nowrap">
EDA
</th>
<th style="white-space:nowrap">
<span class="th-sort">
Immediat
</span>
</th>
<th style="white-space:nowrap">
JNA
</th>
<th style="white-space:nowrap">
Date
</th>
<th style="white-space:nowrap">
Heure début
</th>
<th style="white-space:nowrap">
Heure fin
</th>
<th style="white-space:nowrap">
Puissance
</th>
<th style="white-space:nowrap">
RP
</th>
<th style="white-space:nowrap">
RS
</th>
<th style="white-space:nowrap">
Caractérisation
</th>
<th style="white-space:nowrap">
Commentaire
</th>
<th style="white-space:nowrap">
Source
</th>
<th style="white-space:nowrap">
Date de création
</th>
<th style="white-space:nowrap">
Refus
</th>
<th style="white-space:nowrap" class="th-sortable" data-toggle="class">
</th>
</tr>
</thead>
<tbody>
#if (Model.Count > 0)
{
foreach (var item in Model)
{
#Html.HiddenFor(model => item.ORD_ID)
<tr>
<td>
<input type="checkbox" value="#item.ORD_ID" id="chk_#item.ORD_ID" />
</td>
<td>
#Html.DisplayFor(model => item.EDA_NOM)
</td>
<td>
#(Convert.ToBoolean(item.EDA_IMMEDIAT) ? "Oui" : "Non")
</td>
<td>
#(Convert.ToBoolean(item.EDA_JNA) ? "Oui" : "Non")
</td>
<td>
#if (item.EDA_ORDRE_DATE_DEBUT != null)
{#Html.DisplayFor(model => item.EDA_ORDRE_DATE_DEBUT, "ShortDateTime")}
</td>
<td style="white-space:nowrap">
#if (item.EDA_ORDRE_DATE_DEBUT != null)
{#Html.DisplayFor(model => item.EDA_ORDRE_DATE_DEBUT, "ShortTimeString")}
</td>
<td>
#if (item.EDA_ORDRE_DATE_FIN != null)
{ #Html.DisplayFor(model => item.EDA_ORDRE_DATE_FIN, "ShortTimeString")}
</td>
<td>
#Html.DisplayFor(model => item.EDA_PUISSANCE)
</td>
<td>
#Html.DisplayFor(model => item.EDA_PUISSANCE_RP)
</td>
<td>
#Html.DisplayFor(model => item.EDA_PUISSANCE_RS)
</td>
<td>
#Html.DisplayFor(model => item.Eda_Caracterisation)
</td>
<td>
#Html.DisplayFor(model => item.COMMENTAIRE)
</td>
<td>
#Html.DisplayFor(model => item.SOURCE_NOM)
</td>
<td>
#if (item.EDA_DATE_RECUPEREE != null)
{ #Html.DisplayFor(model => item.EDA_DATE_RECUPEREE, "ShortDateTime")}
</td>
<td>
#Html.DisplayFor(model => item.VAL_REFUS)
</td>
<td >
#if (item.MODIFIABLE == 0)
{
<a class="btn btn-warning editor-container" data-id="#item.ORD_ID" data-toggle="modal"
><i class="fa fa-edit"></i></a>
}
</td>
</tr>
}
}
else
{
<tr>
<td class="text-center " colspan="16">
#VideResult
</td>
</tr>
}
</tbody>
</table>
</div>
<footer class="panel-footer">
<div class="row">
<div class="col-sm-4 ">
<button type="submit" class="btn btn-s-md btn-warning" id="Accepter">Accepter</button>
<button class="btn btn-s-md btn-default" id="Refuser">Refuser</button>
</div>
<div class="col-sm-4 text-center">
</div>
<div class="col-sm-4 text-right text-center-xs">
#Html.PagedListPager(Model, Page_No => Url.Action("Liste",
new
{
eda = ViewBag.eda,
Source = ViewBag.Source
,
datedeb = ViewBag.datedeb
,
datefin = ViewBag.datefin
,
refus = ViewBag.refus
,
page = Page_No
}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast
, new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "TabOrdre",
LoadingElementId = "loader"
}))
</div>
</div>
</footer>
</section>
I have written code to implement search using ajax in asp.net MVC. I have written an action inside my controller (Admincontroller) using partial view which is supposed to fetch data. I want to display the partial view result inside table body in my Index page.
The search function is working fine, but it is not displaying the result inside table body with id "searchresult" (Inside Index page). instead of that it is giving result. I wanted the result from search in table format. now result is displayed like below in http://localhost:1274/Admin/Search.
2786 Mens L/S 4000
here is my Index.cshtml
#model IEnumerable<TestEntityFramework.Models.trProducts>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_AdminLayout.cshtml";
AjaxOptions ajax = new AjaxOptions
{
UpdateTargetId = "searchresult",
Confirm = "Are you sure to start search?",
InsertionMode = InsertionMode.Replace,
LoadingElementId="Loadhere"
};
}
<h2>Index</h2>
<script src="~/scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/scripts/jquery.unobtrusive-ajax.min.js"></script>
<div class="panel-heading">
<div>
#Html.ActionLink("Create New", "Create",null, new{ #class="btn btn- primary" })
</div>
</div>
<div class="panel-body">
<table class="table table-striped table-bordered table-condensed table- hover table-responsive">
<tr>
<th>
#Html.DisplayNameFor(model => model.prod_type)
</th>
<th>
#Html.DisplayNameFor(model => model.prod_name)
</th>
<th>
#Html.DisplayNameFor(model => model.prod_desc)
</th>
<th>
#Html.DisplayNameFor(model => model.prod_price)
</th>
<th>
#Html.DisplayNameFor(model => model.prod_qty)
</th>
<th>
#Html.DisplayNameFor(model => model.prod_category)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.prod_type)
</td>
<td>
#Html.DisplayFor(modelItem => item.prod_name)
</td>
<td>
#Html.DisplayFor(modelItem => item.prod_desc)
</td>
<td>
#Html.DisplayFor(modelItem => item.prod_price)
</td>
<td>
#Html.DisplayFor(modelItem => item.prod_qty)
</td>
<td>
#Html.DisplayFor(modelItem => item.prod_category)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new {id=item.product_id}) |
#Html.ActionLink("Details", "Details", new { id=item.product_id }) |
#Html.ActionLink("Delete", "Delete", new { id=item.product_id })
</td>
</tr>
}
</table>
</div>
<div class="col-lg-8">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>
Product Id
</th>
<th>
Product Name
</th>
<th>
Price
</th>
<th>
</th>
</tr>
</thead>
<tbody id="searchresult">
#Html.Action("Search", new { pr_name = "" })
</tbody>
</table>
#using (Ajax.BeginForm("Search", ajax))
{
<div id="Loadhere">
#Html.TextBox("pr_name")
<button class="btn btn-primary">Search</button>
</div>
}
</div>
and my partialview Search.cshtml looks as below
#model IEnumerable<TestEntityFramework.Models.trProducts>
#foreach(var m in Model)
{
<tr>
<td>
#m.product_id
</td>
<td>
#m.prod_name
</td>
<td>
#m.prod_price
</td>
</tr>
}
I have 2 forms on a single razor view that open in seperate dialog boxes. The forms are submitted using jquery post..
First form works perfectly but the second form isnt recognised at all and when I try to serializr the data it returns an empty string.
Code below:
#using (Html.BeginForm("SaveElectricReading", "Store", FormMethod.Post, new { id = "frmSaveElectricReading" }))
{
<div id="electricDialog" style="display: none;" title="Electric Readings">
<p>
Please ensure the electric readings have been entered!
</p>
<table width="100%">
<tr>
<th>
Serial:
</th>
</tr>
<tr>
<td>
<input type="text" name="Serial" />
</td>
</tr>
<tr>
<th>
Reading:
</th>
</tr>
<tr>
<td>
<input type="text" name="Reading" />
</td>
</tr>
<tr>
<th>
Comment:
</th>
</tr>
<tr>
<td>
<div class="textwrapper">
<textarea rows="5" cols="10" name="Comment"></textarea>
</div>
</td>
</tr>
</table>
</div>
}
#using (Html.BeginForm("SaveWaterReading", "Store", FormMethod.Post, new { id = "myform" }))
{
<div id="waterDialog" style="display: none;" title="Water Readings">
<p>
Please ensure the water readings have been entered!
</p>
<table width="100%">
<tr>
<th>
Serial:
</th>
</tr>
<tr>
<td>
<input type="text" name="WaterSerial" />
</td>
</tr>
<tr>
<th>
Reading:
</th>
</tr>
<tr>
<td>
<input type="text" name="WaterReadingsdfsdf" />
</td>
</tr>
<tr>
<th>
Comment:
</th>
</tr>
<tr>
<td>
<div class="textwrapper">
<textarea rows="5" cols="10" name="WaterComment"></textarea>
</div>
</td>
</tr>
</table>
</div>
}
function showWaterDialog() {
var $dialog = $('#waterDialog').dialog({
autoOpen: false,
modal: true,
width: 400,
height: 400,
buttons: {
Submit: function () {
// $('#frmCreateStore').submit();
var data = $('#frmSaveWaterReading');
$.post("/Store/SaveWaterReading",
$("#frmSaveWaterReading").serialize(),
function () {
$("#waterDialog").dialog("close");
});
//$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
$dialog.dialog('open');
}
In the jquery function for showing the dialog with the form in it, I needed to add that dialog content to the second form on the page as follows:
$("#waterDialog").parent().appendTo($("form").eq(1)[0]);