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

  • Home
  • SEARCH
  • 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 4097670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:12:11+00:00 2026-05-20T20:12:11+00:00

I have data of matrix stored in table as below tables: MatrixDimensions – MatrixId,

  • 0

I have data of matrix stored in table as below tables:

  • MatrixDimensions – MatrixId, NoOfRows, NoOfCol
  • MatrixValues – MatrixId, RowNo, ColNo, Value

How can I make jqGrid to take no. of rows & columns dynamically
and also display the serialized data in matrix? Is there a direct way or will I have to implement for loops to upload the data in matrix?

Can I display rows as columns and columns as rows (so having column headers vertically aligned)?

Can I enable only inline editing and disable form based editing?

  • 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-20T20:12:12+00:00Added an answer on May 20, 2026 at 8:12 pm

    I just wrote the answer to another question where I described how to create the grid with dynamic number of columns (number of rows is always dynamic in jqGrid). It seems to me this way you can display any matrix. In you case you can probably make the code simpler because you can use generic column names like “1”, “2”, etc. (or “Col. 1”, “Col. 2”, etc.) and so on.

    I modified the code so that it uses array of arrays (matrix) instead of the array on objects with named properties. So jqGrid will looks like this:

    enter image description here

    or this:

    enter image description here

    depending on the input JSON data.

    The full demo can be found here. The full JavaScript code of the demo you can find below:

    var mygrid=jQuery("#list"),
        cmTxtTemplate = {
            width:40,
            align:"center",
            sortable:false,
            hidden:true
        }, currentTemplate = cmTxtTemplate, i,
        cm = [], maxCol = 30, dummyColumnNamePrefix = "", //"Col. ",
        clearShrinkToFit = function() {
            // save the original value of shrinkToFit
            var orgShrinkToFit = mygrid.jqGrid('getGridParam','shrinkToFit');
            // set shrinkToFit:false to prevent shrinking
            // the grid columns after its showing or hiding
            mygrid.jqGrid('setGridParam',{shrinkToFit:false});
            return orgShrinkToFit;
        },
        setGridWidthAndRestoreShrinkToFit = function(orgShrinkToFit,width) {
            // restore the original value of shrinkToFit
            mygrid.jqGrid('setGridParam',{shrinkToFit:orgShrinkToFit});
            mygrid.jqGrid('setGridWidth',width);
        },
        dummyTestRegex = new RegExp(dummyColumnNamePrefix+"(\\d)+"),
        counter = 1;
    
    // Add dummy hidden columns. All the columns has the same template
    for (i=0;i<maxCol;i++) {
        cm.push({name:dummyColumnNamePrefix+(i+1),template:currentTemplate});
    }
    
    mygrid.jqGrid({
        url:'Matrix1.json',
        datatype: "json",
        // colNames will be set based on the properties for JSON input
        colModel:cm,
        height:"auto",
        rownumbers:true,
        loadonce:true,
        gridview: true,
        rowNum: 1000,
        sortname:"",
        jsonReader: {
            cell: "",
            id: function (obj) {
                return "id"+counter++;
            },
            page: function (obj) {
                var rows = obj.rows, colModel = mygrid[0].p.colModel,
                    cmi, width = 0, iFirstDummy, cols, orgShrinkToFit,
                    showColNames = [], hideColNames = [];
    
                if (typeof(rows) === "undefined" || !(rows.length>0)) {
                    // something wrong need return
                    return obj.page;
                }
    
                // find the index of the first dummy column
                // in the colModel. If we use rownumbers:true,
                // multiselect:true or subGrid:true additional
                // columns will be inserted at the begining
                // of the colModel
                iFirstDummy = -1;
                for(i=0;i<colModel.length;i++) {
                    cmi = colModel[i];
                    if (dummyTestRegex.test(cmi.name)) {
                        iFirstDummy = i;
                        break;
                    }
                }
                if (iFirstDummy === -1) {
                    // something wrong need return
                    return obj.page;
                }
    
                orgShrinkToFit = clearShrinkToFit();
    
                // we get the first row of the JSON data
                cols = rows[0].length;
    
                // fill the list of unused columns
                for(i=0;i<colModel.length;i++) {
                    cmi = colModel[i];
                    if (i<iFirstDummy+cols) {
                        cmi.width = currentTemplate.width;
                        showColNames.push(cmi.name);
                    } else {
                        hideColNames.push(cmi.name);
                    }
                }
                mygrid.jqGrid('showCol',showColNames);
                mygrid.jqGrid('hideCol',hideColNames);
                setGridWidthAndRestoreShrinkToFit(orgShrinkToFit,
                    cols*currentTemplate.width);
    
                return obj.page;
            }
        }
    });
    $("#readJson1").click(function() {
        mygrid.jqGrid('setGridParam',
                      {datatype:'json',page:1,url:'Matrix1.json'})
              .trigger('reloadGrid');
    });
    $("#readJson2").click(function() {
        mygrid.jqGrid('setGridParam',
                      {datatype:'json',page:1,url:'Matrix2.json'})
              .trigger('reloadGrid');
    });
    

    The simplest way to transpose the matrix (reflect it over its main diagonal) is on the server. If you can’t do this, you can create and fill the transposed matrix inside of page function (see my code above) and just replace the row part of the obj with the transposed matrix.

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

Sidebar

Related Questions

I have data from a table in a database (string) that contain text and
I have a file where a data structure containing 6 columns is stored side
I have huge data matrices stored in a MATLAB M-file and I will explain
I have data in a MySQL database. I am sending the user a URL
I have data coming from the database in the form of a DataSet .
I have data that looks like CUSTOMER, CUSTOMER_ID, PRODUCT ABC INC 1 XYX ABC
I have data from MySQL showing all organisations a customer got, with all details
I have data in this form, Article ID Company A Company B Company C
I have data that needs to be executed on a certain background thread. I
I have data that looks like this: entities id name 1 Apple 2 Orange

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.