3

C# allows a reserved word to be used as a property name via the at sign. e.g.

// In ASP.NET MVC, we use @class to define 
// the css class attribute for some HtmlHelper methods.
var htmlObject = new { readonly = "readonly", @class = "ui-state-highlight" }

I want to do the same in JavaScript. e.g.

function makeGrid(grid, pager) {
    grid.jqGrid({
        caption: 'Configurations',
        colNames: ['Id', 'Name'],
        colModel: [
            { name: 'Id', index: 'Id' },
            { name: 'Name', index: 'Name', editable: true, 
              editoptions: { readonly: 'readonly', class: 'FormElement readonly' } },
          ],
        pager: pager,
        url: 'www.example.com/app/configurations") %>',
        editurl: 'www.example.com/app/configurations/edit") %>'
    }).navGrid(pager, { edit: true, add: false, del: false, search: false }, {}, {}, {});
}

Note class: 'FormElement readonly' is supposed to set the css class value on jqGrid's edit dialog, but IE errors out on the reserved word.

Is there an escape character in JavaScript too? #class? @class? &class? Otherwise, how might I tell jqGrid to set the css class on the popup editor? Thank you.

Community
  • 1
  • 1
Robert Claypool
  • 4,262
  • 9
  • 50
  • 61

4 Answers4

10

I think in this context, quoting class should work as it's the name of a property on an object literal i.e.

editoptions: { readonly: 'readonly', 'class': 'FormElement readonly' } },
Russ Cam
  • 124,184
  • 33
  • 204
  • 266
2

I dont know jqGrid but I would imagine 'class' would work.

James Westgate
  • 11,306
  • 8
  • 61
  • 68
1

Use "className".

James
  • 109,676
  • 31
  • 162
  • 175
0

You can also use @class in jQuery

griegs
  • 22,624
  • 33
  • 128
  • 205