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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:02:22+00:00 2026-06-02T05:02:22+00:00

I have a jqGrid, and one column should have a default value when adding

  • 0

I have a jqGrid, and one column should have a default value when adding a new row. I have followed the documentation, but the value never appears.

This is the column from the colModel:

{name: 'Lt', index: 'Lt', width: 25, editable: true, editoptions: {defaultValue: 'N'}}

And this is how I call addRowData:

$("#grid").addRowData(-1,
    { Datum: $.datepicker.formatDate("yy-mm-dd", new Date()) }, "first", true)

As far as I can see, I’m doing it by the book!

Complete grid def:

    $("#dagbok_grid").jqGrid({
        datatype: 'json',
        mtype: 'GET',
        colNames: [
            'a',
            'b',
            'c',
            'd',
            'e',
            'f',
            'g',
            'h',
            'i',
            'j',
            'k',
            'l',
            'm',
            'n',
            'o',
            'p',
            'q',
            'r',
            's'],
        colModel: [
          { name: 'a', index: 'a', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
          { name: 'b', index: 'b', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
          { name: 'c', index: 'c', width: 70, formatter: 'date', editable: true, editrules: { required: true }, editoptions: { dataInit: function (elem) { $(elem).datepicker(); } } },
          { name: 'd', index: 'd', width: 65, editable: true, formatter: 'date', formatoptions: { srcformat: 'H:i:s', newformat: 'ShortTime' }, editrules: { time: true} },
          { name: 'e', index: 'e', width: 80, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'f', index: 'f', width: 100, editable: true, edittype: 'textarea', editoptions: {rows: '7'} },
          { name: 'g', index: 'g', width: 80, editable: true, edittype: 'textarea', editoptions: { rows: '7'} },
          { name: 'h', index: 'h', width: 80, editable: true, editrules: { maxValue: 50} },
          { name: 'i', index: 'i', width: 120, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'j', index: 'j', width: 200, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'k', index: 'k', width: 70, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'l', index: 'l', width: 70, editable: true, editrules: { maxValue: 10} },
          { name: 'm', index: 'm', width: 25, editable: true, editoptions: { defaultValue: 'N'} },
          { name: 'n', index: 'n', width: 70, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
          { name: 'o', index: 'o', width: 25, editable: true, editrules: { custom: true, custom_func: chkLongitudTecken} },
          { name: 'p', index: 'p', width: 80, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
          { name: 'q', index: 'q', width: 80, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'r', index: 'r', width: 100, editable: true, editrules: { maxValue: 50} },
          { name: 's', index: 's', width: 65, edittype: 'select', editable: true, formatter: 'select' },
        ],
        sortname: 'c',
        sortorder: 'desc',
        shrinkToFit: false,
        viewrecords: true,
        gridview: true,
        onSelectRow: function (id) {
            if (id && id !== lastsel) {
                jQuery('#dagbok_grid').saveRow(lastsel);
                lastsel = id;
            }
            jQuery('#dagbok_grid').editRow(id, true);
        },
        height: 400,
        editurl: '@Url.Action("SaveGridRow")',
        caption: 'my grid'
    });

I also later on add select-values to some cols:

    $.ajax({
        type: 'GET',
        url: '@Url.Action("GetGridComboValues")',
        async: false,
        success: function (data) {
            var grid = $("#dagbok_grid");
            grid.setColProp("e", { editoptions: { value: data.kallor} });
            grid.setColProp("i", { editoptions: { value: data.rubriker} });
            grid.setColProp("j", { editoptions: { value: data.verksamheter} });
            grid.setColProp("k", { editoptions: { value: data.opPadrag, dataEvents: [{ type: 'change', fn: function (e) {
                $.ajax({
                    type: "GET",
                    url: '@Url.Action("GetVerksamhetskod")',
                    data: { "opPadragId": e.currentTarget.value },
                    dataType: 'json',
                    success: function (data) {
                        var selr = jQuery('#dagbok_grid').jqGrid('getGridParam', 'selrow');
                        jQuery("#dagbok_grid").jqGrid('setCell', selr, "l", data);
                    }
                });
            }
            }]
            }
            });
            grid.setColProp("q", { editoptions: { value: data.medier} });
            grid.setColProp("s", { editoptions: { value: data.regioner} });
        }
    });

Add and delete code

    $("#toolbarAddButton")
        .button()
        .click(function () {
            $("#dagbok_grid").addRowData(-1, { Datum: $.datepicker.formatDate("yy-mm-dd", new Date()) }, "first", true)
        });

    $("#toolbarDeleteButton").click(function () {
        var radid = $("#dagbok_grid").jqGrid("getGridParam", "selrow");
        if (radid != null) {
            var su = $("#dagbok_grid").jqGrid("delRowData", radid);
            $("#dagbok_grid").jqGrid("delGridRow", radid, { url: '@Url.Action("DeleteGridRow")', reloadaftersubmit: false });

        }
    })

Save executes when the user press entering while in edit mode.

  • 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-06-02T05:02:25+00:00Added an answer on June 2, 2026 at 5:02 am

    First of all you defined editoptions: { defaultValue: 'N'}. You can read in the documentation of the editoptions

    The option can be string or function. This option is valid only in
    Form Editing module
    when used with editGridRow method in add mode. If
    defined the input element is set with this value if only element is
    empty. If used in selects the text should be provided and not the key.
    Also when a function is used the function should return value.

    What you want is that default value will be set during filling the grid body and not during editing. For the purpose exist defaulValue formatter option, but it will be used only for some predefined formatters (see the documentation).

    You can solve the problem either by usage of custom formatter or, if you use addRowData method directly, by adding explicit the value of Lt column.

    I don’t recommend to use low-level method addRowData which is slow and will be mostly used in wrong way. You used for example -1 as the rowid. If you would execute the same statement more as one time you will have id duplicates which is error and can follow to very strange effects. If you want that jqGrid generate the unique ids itself you should use undefined as the rowid parameter.

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

Sidebar

Related Questions

Some quick searching only turns up adding a new row to a jQGrid via
I have some data from JQGrid that should be exported to excel. So, we
I have jqgrid and in that I have one custom navigation button to export
I have jqGrid with two columns, one being hidden. For some reason in FireFox
i have a page with a jqgrid on it with filter row at the
I know jqGrid can hide the column in grid but visiable in edit form.
I have jqGrid 3.5 (full) mostly working. I have it retrieving data with the
I have a jqGrid on a page and users can click a button to
I have a jqGrid with which users will select records. A large number of
I have a jqGrid in grouping mode that works fine on initial load. However,

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.