JQGrid: unable to get position with rowId

I am using jqGrid and I have a heck of a time inserting a new row at a specific location. I have a rowId, but when I make a call to determine which position (row index), I get null back. I work with a table:

var grid = jQuery("#myTable");
grid.jqGrid({
    datatype: "local",
    colNames:['id','Type', 'Name', 'Total','In','Out'],
    colModel:[
            { name: 'id', index: 'id', hidden: true, align:"center"},     
            {name:'type',index:'type', width:10, sortable:true, align:"center"},
            {name:'name',index:'name', width:40, sortable:true, align:"center"},
            {name:'total',index:'total', width: 10, sortable:false, align:"center"},
            {name:'in',index:'in', width:10, sortable:true, align:"center"},
            {name:'out',index:'out', width:10, sortable:true, align:"center"}
    ],
    width: "600",
    height: "900"
  });

      

But when I call:

var dataIds = jQuery("#myTable").getDataIDs();

      

I am returning the following:

Level 3.xpusdscdw,Level 3.scoach3,Level 3.xpusdscvs,Level 3.xpusdscah,Level 3.xpusdsctotem,Level 3.xpusdscsc

      

But when I try to get the row index of any of them, the result is returned null. This is what I am trying to do:

var position = jQuery("#myTable").getInd(rowId,false);
alert("Position is: "+position+" for "+rowId);

      

And then I check and see that I am back (with a warning), I see this:

Position is: false for Level 03.xpusdscvs

      

?

What gives? getInd should return the rowId row index when you pass false as the second parameter. A little help?

thank

0


source to share


1 answer


I have to start by noticing what limitations id

HTML has. It cannot be a single line. First of all, it must be unique on the page. Then it must follow the CSS and HTML requirements for IDs. Requirements differ slightly in different versions of CSS and different versions of HTML. For example, in the CSS 2.1 spec, you can read the following (see here ):

In CSS, identifiers (including element names, classes, and identifiers in selectors) can only contain the characters [a-zA-Z0-9] and ISO 10646 characters U + 00A0 and above, plus the hyphen (-) and underscore (_); they cannot start with a number, two hyphens, or hyphens with a number. Identifiers can also contain escaped characters and any ISO 10646 in the form of a numeric code (see next paragraph). For example, the identifier "B & W?" can be written as "B \ & W \?" or "B \ 26 W \ 3F".

In the HTML5 spec you can read (see here )

The id attribute specifies its unique element identifier (ID).

The value must be unique among all identifiers in the home subtree and must contain at least one character. The value must not contain any whitespace characters.

In addition, if you use special characters, such as .

or other metacharacters inside jQuery selectors, you should avoid character with two backslashes: \\

. See here for details .

jqGrid uses the $. jgrid.jqID to avoid possible metacharacters:



var myElement = $('#' + $.jgrid.jqID(someId));

      

If you want to make your life easier, I would recommend using only characters [A-Za-z]

, numbers, [0-9]

or _

or -

inside identifiers. Also, I would recommend that you do not use IDs that were only different in case. HTML is in most cases case insensitive, so it is better to use either [a-z]

or [a-z]

. In addition, you must (but do not have to) use a letter as the first character of the id. A simple rule can save you time in the future.

In your case, ideals such as xpusdscdw

, scoach3

, xpusdscvs

, xpusdscah

, xpusdsctotem

, xpusdscsc

without prefix "Level 3"

ideal.

Now, back to your main question. If you have id

strings in a variable rowid

that is inside an HTML table, you can use the following code to get the index of the string if the string is:

var rowid = "xpusdscdw";
var myRow = $("#" + rowid);
alert("row index: " + myRow[0].rowIndex);

      

In the code, I am using the fact that rowid

is the element id of the <tr>

element <table>

. See Description rowIndex

here .

0


source







All Articles