Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:07:26+00:00 2026-05-17T15:07:26+00:00

In my attempt to enable sorting and filtering in conjunction with the MVC contrib.

  • 0

In my attempt to enable sorting and filtering in conjunction with the MVC contrib. grid I have decided to use a Viewmodel which contains the grid data plus the sorting and filtering information. I added a form under the grid and the Viewmodel is used to maintain the state of the form and to carry the data for the grid:

public class GridViewModel<T>
    {
        public int Page {get; set;} // current page of grid
        public string OrderBy {get; set;} // name of the column
        public bool Asc {get; set;} 
        public string Operation {get; set;} // SW - Startswith, C - Contains
        public string Column {get; set;} // name of the column where operation takes place
        public string Argument {get; set;} // argument for operation
        public int RowsPerPage {get; set;} // visible number of rows per page

        public List<T> Data {get; set;}

        public GridViewModel(List<T> Data)
        {
            this.Data = Data;
        }
        public GridViewModel()
        {
            Page = 1;
            Asc = true;
            RowsPerPage = 10;
            Argument = "";
        }

        public int getNumberofPages()
        {
            return (int) Math.Ceiling(Convert.ToDouble(Data.Count) / Convert.ToDouble(RowsPerPage));
        }
    }

The form is created using HTMLHelpers and by passing in the Viewmodel.

The Viewmodel is created in a service method like this (not complete):

public GridViewModel<Bla> GetGridData(GridViewModel<Bla> GridViewModel)
        {
            IOrderedEnumerable<Bla> list = GetAllBlas();

            string Argument = GridViewModel.Argument.Trim();
            switch (GridViewModel.Column)
            {
                case "Age":
                    switch (GridViewModel.Operation)
                    {
                        case "SW":
                            list = list.Where(c => c.Age.ToString().StartsWith(Argument)).OrderBy(c => c.ProposalDateTime);
                            break;
                        case "C":
                            list = list.Where(c => c.Age.ToString().Contains(Argument)).OrderBy(c => c.ProposalDateTime);
                            break;
                        default:
                            break;
                    }
                    break;

                default:
                    break;
            }

            int start_index = (GridViewModel.RowsPerPage * GridViewModel.Page) - GridViewModel.RowsPerPage;

            switch (GridViewModel.OrderBy)
            {
                case "Age":
                    list = GridViewModel.Asc == true ? list.OrderBy(c => c.Age) : list.OrderByDescending(c => c.Age);
                    break;
                case "ProposalDateTime":
                    list = GridViewModel.Asc == true ? list.OrderBy(c => c.ProposalDateTime) : list.OrderByDescending(c => c.ProposalDateTime);
                    break;
                case "UpdateDateTime":
                    list = GridViewModel.Asc == true ? list.OrderBy(c => c.UpdateDateTime) : list.OrderByDescending(c => c.UpdateDateTime);
                    break;
                default:
                    list = GridViewModel.Asc == true ? list.OrderBy(c => c.ProposalDateTime) : list.OrderByDescending(c => c.ProposalDateTime);
                    break;
            }

            int number_of_rows = list.Count();
            if (start_index > number_of_rows)
            {
                start_index = 0;
            }

            GridViewModel.Data = list.Skip<Bla>((int)start_index).Take<Bla>((int)GridViewModel.RowsPerPage).ToList();

            return GridViewModel;
        }

This works but does not feel right yet …

I am just wondering whether this code could be improved – has someone done something similar? Any feedback would be very much appreciated. Many thanks in advance.

Best wishes,

Christian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:07:27+00:00Added an answer on May 17, 2026 at 3:07 pm

    The closest thing to an answer can be found here (proposed by: Sergey Prokhorenko):

    http://sprokhorenko.blogspot.com/2009/12/dedicated-to-my-wife.html

    It is jqgrid specific but provided me with some ideas.

    Christian

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create wrapper class, which will enable keys duplicates while default hash
I'm using Spring + JPA + Hibernate. I'm trying to enable Hibernate's second level
I've spent the past two days just trying to enable the sending of email
Wordpress' documentation suggests adding the following to functions.php to enable what I want to
I have built a Air 2/Flex 4 kiosk application with Flash Builder 4. Currently
How can I use WIA and Twain in C#? The TWIAIN/C# example found at
I am deploying a mod_wsgi application on top of Apache, and have a client
I want to keep a log with the attempted log-in to a machine. The
How can you disable the send -button if there is one or more input
Check this error and please help me. 2009-07-24 15:58:34.209 LBS[2636] Host 'staging.common.virtualearth.net' not found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.