473,651 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MVC: Custom sorting for HTML table

Hi,

I was wondering how I can sort a HTML table the smartest way. I've got
the following table:

<table id="customersTa ble" class="dataTabl e">
<thead>
<tr>
<th>Kundenavn </th>
<th>POB kunde nr.</th>
<th>SAP kontrakt nr.</th>
<th>Start dato</th>
<th>Brugere</th>
</tr>
</thead>
<tbody>
<% foreach (var c in ViewData["Customers"] as List<Customer>)
{ %>
<tr>
<td><%= Html.ActionLink (c.Name, c.ID.ToString() ,
"Customers" ) %></td>
<td class="alignRig ht"><%= c.POBNo %></td>
<td class="alignRig ht"><%= c.SAPContractNo %></td>
<td class="alignRig ht"><%=
c.StartDate.ToS tring("dd-MM-yy") %></td>
<td class="alignRig ht"><%= c.Users.Count %></td>
</tr>
<% } %>
</tbody>
</table>

Where each header cell should be clickable to sort the choosen column.

The table datasource is a List<Customer>, published using LINQ to SQL.
Heres the controller:

AdvoforumDataCo ntext advoforum = new AdvoforumDataCo ntext();
List<Customercu stomers = advoforum.GetCu stomers();
ViewData["Customers"] = customers;
return View();

Could you give me a hint how to do this the "best" way?
Jul 8 '08 #1
2 3111
you have two options. sort client side using javascript (which is how i'd do
it), or add an anchor on the column heads and sort server side:

<th><a href="list/sort/1">Kundenavn </a></th>
<th><a href="list/sort/2">POB kunde nr.</a></th>

where you add a sort method to the list controller.

-- bruce (sqlwork.com)
"Tommy Holm Jakobsen" wrote:
Hi,

I was wondering how I can sort a HTML table the smartest way. I've got
the following table:

<table id="customersTa ble" class="dataTabl e">
<thead>
<tr>
<th>Kundenavn </th>
<th>POB kunde nr.</th>
<th>SAP kontrakt nr.</th>
<th>Start dato</th>
<th>Brugere</th>
</tr>
</thead>
<tbody>
<% foreach (var c in ViewData["Customers"] as List<Customer>)
{ %>
<tr>
<td><%= Html.ActionLink (c.Name, c.ID.ToString() ,
"Customers" ) %></td>
<td class="alignRig ht"><%= c.POBNo %></td>
<td class="alignRig ht"><%= c.SAPContractNo %></td>
<td class="alignRig ht"><%=
c.StartDate.ToS tring("dd-MM-yy") %></td>
<td class="alignRig ht"><%= c.Users.Count %></td>
</tr>
<% } %>
</tbody>
</table>

Where each header cell should be clickable to sort the choosen column.

The table datasource is a List<Customer>, published using LINQ to SQL.
Heres the controller:

AdvoforumDataCo ntext advoforum = new AdvoforumDataCo ntext();
List<Customercu stomers = advoforum.GetCu stomers();
ViewData["Customers"] = customers;
return View();

Could you give me a hint how to do this the "best" way?
Jul 8 '08 #2
On Tue, 8 Jul 2008 09:02:10 -0700, bruce barker
<br*********@di scussions.micro soft.comwrote:
>you have two options. sort client side using javascript (which is how i'd do
it), or add an anchor on the column heads and sort server side:

<th><a href="list/sort/1">Kundenavn </a></th>
<th><a href="list/sort/2">POB kunde nr.</a></th>

where you add a sort method to the list controller.

-- bruce (sqlwork.com)
"Tommy Holm Jakobsen" wrote:
>Hi,

I was wondering how I can sort a HTML table the smartest way. I've got
the following table:

<table id="customersTa ble" class="dataTabl e">
<thead>
<tr>
<th>Kundenavn </th>
<th>POB kunde nr.</th>
<th>SAP kontrakt nr.</th>
<th>Start dato</th>
<th>Brugere</th>
</tr>
</thead>
<tbody>
<% foreach (var c in ViewData["Customers"] as List<Customer>)
{ %>
<tr>
<td><%= Html.ActionLink (c.Name, c.ID.ToString() ,
"Customers" ) %></td>
<td class="alignRig ht"><%= c.POBNo %></td>
<td class="alignRig ht"><%= c.SAPContractNo %></td>
<td class="alignRig ht"><%=
c.StartDate.To String("dd-MM-yy") %></td>
<td class="alignRig ht"><%= c.Users.Count %></td>
</tr>
<% } %>
</tbody>
</table>

Where each header cell should be clickable to sort the choosen column.

The table datasource is a List<Customer>, published using LINQ to SQL.
Heres the controller:

AdvoforumDataC ontext advoforum = new AdvoforumDataCo ntext();
List<Customerc ustomers = advoforum.GetCu stomers();
ViewData["Customers"] = customers;
return View();

Could you give me a hint how to do this the "best" way?
Thank you. I've found a way to do it client side using Javascript.

- Tommy
Jul 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2378
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that field... This grid displayes results based on users search.. public static int numberDiv; private void Page_Load(object sender, System.EventArgs e) {
4
2812
by: Gareth Gale | last post by:
I'm trying to implement a way of allowing a user to sort a HTML table via Javascript on the client. I've seen lots of samples where single column sorting (asc or desc) is shown, but I'd like nested sorting i.e. sort by col1 asc, then by col2 desc etc. Can anyone help ?
0
1498
by: Lenny | last post by:
Hello, I have an html table template which I want to turn into ASP.NET custom control. I want to utilize the best features of OOP. I want to be able to create columns headings dynamically, add buttons to the footer of the table, etc. A datagrid control wont work for me, because I want to have custom buttons images for paging and sorting. Here is one thing I have the most difficulty with: I need a way to have a "master" custom table...
8
10566
MVC
by: Alisa | last post by:
Hi, I am reading a lot about MVC pattern and I wonder - are there any known programs that were developed and do not implement MVC? I thought Outlook is one becuase the item object is not seperated from it's UI/ form - but I am not sure... Does any one have a stronger example? Thanks, Alisa
5
2435
by: meonimarco | last post by:
Hi to all. I woud implement MVC with wxPython. Is it possible? Is there anyone that have experience in this? The only correct example according to Observer Pattern that i found on web is not the formal implementation of MVC (is Document/View) and is implemented with gtk... How can i translate this gtk example in wx? Does exist a tutorial, a archive of example or anything about MVC in wx? Thanks all!
0
1555
by: Roy | last post by:
Hey all, I must be losing my touch. I have made many pages in the 1.1 framework that utilize custom bidirectional paging in datagrids. We've converted over to 2.0 and I've been trying to use the built-in functionality of gridviews and objectdatasource's to accomplish the same thing (w/o resorting to the 1.1 methodology). I discovered two very nice and comprehensive articles concerning this: Custom Paging in ASP.NET 2.0 with SQL Server...
0
1035
by: Georg Altmann | last post by:
Maric Michaud schrieb: Yes, I did. But as I explained in my previous message, the whole Qt model-view framework doesn't seem fit any data which can not be handled as QVariant and thus as a value type. Except they always handle simple data. I don't see how to get around the QVariant limitatation. Also the data should be displayed in a graphical manner (maybe a QGraphicsScene/QGraphicsView or mabye custom
13
1408
by: Author | last post by:
I happened to see this asp.net MVC tutorial at http://www.asp.net/learn/mvc/tutorial-01-cs.aspx Indeed as the author says it is gonna look like classic ASP at the very beginning of this tutorial. I think form post with an action (which is classic asp style) like <form method="post" action="/Home/CreateNew">
5
4932
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.