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 7627121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:25:04+00:00 2026-05-31T05:25:04+00:00

Question : using jqgrid to show data of a table. table has foreign key

  • 0

Question:

using jqgrid to show data of a table. table has foreign key and we want to show text of its foreign key instead of Id. I also want that user can sort and filter over the foreign keys.

Example:

  • Person Table: Id,Name,EducationId(foreign key for Education Table)
  • Education able: Id,Name

We want to show each person with the name of his/her education name in a jqgrid.

  1. If user click over education column, it sort according to Education Name(Not Education Id)
  2. If User want to filter over education, we show a dropdown(selector) that contain education Names,after user select one, the filter contain EducationId as sField and Id of selected value as sValue

My Solution:

var items1 = {@Html.GetEduType()};

$(function () {
        $("#list").jqGrid({
            url: '/Home/GridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Name','Education'],
            colModel: [
          { name: 'Name', index: 'Name' },
          { name: 'EducationId', index: 'Education.Name', search: true, 
             stype: 'select', searchoptions: { value: items1, sopt: ['eq', 'ne'] },
             formatter: 'select' , editoptions: { value: items1 }}],            
            viewrecords: true});
$("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true });
  1. With this code, Home/GetData just send Person.Id, Person.Name, Person.EducationId as json data and it is really good to not send more data than client needs. Also it send relation between Education Id and Name once and these data used for showing name instead of id in grid, and also to create dropdown value and text.
  2. I ignore to write other properties like pager, pagesize, etc
  3. @Html.GetEduType() is razor server side function. It just returns pairs like
    [Education Id]:[Education Name]. For example: (1:'Diploma',2:'M.S.',...) (I just use it to get education data once and did not use UrlData)
    (Yes, I use it in ASP.Net MVC 3, but its not an important point)

My Problem:
It work great for showing data and sorting Education according to its name. But when I want to filter Education it send index value(Education.Name) instead of name value (EducationId) in Http Post sField to server. This problem will be solved just by sending name value instead of index value.

Thanks.

  • 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-31T05:25:05+00:00Added an answer on May 31, 2026 at 5:25 am

    I solved my problem in this way:

    1. First of all, I handle beforeSearch event:

      .filterToolbar({ stringResult: true, beforeSearch: searchPreparation })
      
    2. Here is searchPreparation function:

      function searchPreparation(grid) {
        if (grid == undefined)
            grid = $(this);
        else
            grid = $(grid);
        var postData = grid.jqGrid('getGridParam', 'postData');
        var searchData = jQuery.parseJSON(postData.filters);
        var gridCol = grid.getGridParam("colModel");
        for (var i = 0; i < searchData.rules.length; i++) {
            for (var j = 0; j < gridCol.length; j++) {
                if (gridCol[j].index != gridCol[j].name && searchData.rules[i].field == gridCol[j].name) {
                    searchData.rules[i].field = gridCol[j].index;
                    break;
                }
            }
        }
        grid.jqGrid('setGridParam', { postData: { filters: JSON.stringify(searchData)} });
        return false;
      }
      

    In searchPreparation first I get post data and parse it. After that I search for columns that their indexes are not equal to their name and find that whether is there any filter with these columns. If there is any column, I replace field with index.
    Finally I set the post data. Notify that data convert to JSON with JSON.stringify that you can find it here.

    I use this function for filter data with dropdown either (use value of drop down’s items not text)

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

Sidebar

Related Questions

I am using jqgrid and I want to have a tooltip that is a
I'm using jqGrid for a table input and setting up the url as a
Similar question: Using Silverlight for an entire website? That question is over 2 years
This is a question that I know has been asked here and several other
I had a question using Perl's readdir(). I want to gather all the files
Its like I have multiselect option in Jqgrid in which i want to pass
Similar to This Question using linq to SQL , but I don't want to
I'm using jqGrid to display some data on a page. Within the controller action,
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
Question: Using Ruby it is simple to add custom methods to existing classes, but

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.