Forum


23:53

05/05/2011

Table contains composite primary key which are passed as _id1 , _id2 columns using definition below. If row is deleted, those values are *not* passed to delete or edit url handler in server.
jqGridd passes only surrogate id (row number) to server. It is impossible to find composite keys using row number since records may be already deleted by other users during editing.
How to implement delete in server if composite primary keys are used ?
Composite primary key columns can contain any characters. Should I create single key from them? How to encode spaces and other character which are not allowed in jqGrid ids ?
Also why aftersubmit method is not called if row is edited?
var lastSel;
$(function () {
var grid = $("#grid");
grid.jqGrid({
scroll: 1,
datatype: "json",
mtype: 'POST',
toolbar: [true, "top"],
colModel: [
{ name: 'source', editable: true },
{ name: 'est', editable: true },
{ name: 'eng', editable: true },
{ name: 'rus', editable: true },
{ name: 'fin', editable: true },
{ name: 'lvl', editable: true },
{ name: 'ger', editable: true },
{ name: 'istopic', editable: true },
{ name: 'critical', editable: true },{ name: '_id1',
editable: true, editrules: { edithidden: true }, hidden: true },
{ name: '_id2',
editable: true, editrules: { edithidden: true }, hidden: true
}],
ondblClickRow: function (id) {
if (id && id !== lastSel) {
grid.restoreRow(lastSel);
lastSel = id;
}
grid.editRow(id, true);
},
rowNum: 100,
autoencode: true,
gridview: true,
pager: '#pscrolling',
sortname: 'est',
viewrecords: true,
sortorder: "asc"}).navGrid("#pscrolling", { edit: true, add: true, del: true, refresh: true, search: true },
{savekey: [true, 13],
reloadAfterSubmit: true,
jqModal: false,
closeOnEscape: true,
closeAfterEdit: true,
url: '<%= ResolveUrl("~/Grid/Save")%>',
afterSubmit: function (response, postdata) {
if (response.responseText == "Success") {return [true, response.responseText]
}
else {
return [false, response.responseText]
}
}
},// Add options
{},// Delete options
{
url: '<%= ResolveUrl("~/Grid/Delete")%>',
closeOnEscape: true,
afterSubmit: function (response, postdata) {
if (response.responseText == "Success") {
return [true, response.responseText]
}
else {
return [false, response.responseText]
}
}
}
);
});
00:25

10/08/2009

You have many possibilities to do this: serializeDelData, delData, onclickSubmit. The event handle serializeDelData gives you the most direct way. The opton delData is mostly for the posting additional static data to the server, but you can try to use an object having functions as the properties, like one do this with postData jqGrid parameter. I think it should work. The last way would be to use onclickSubmit which has rp_ge as the first parameter. You can modify rp_ge.url and place the information about the second id part as parameter in the url.
Moreover you don't wrote what information you use as the id of your grid. If you would construct id as (id1 + '_' + id2) then you can easy split the id information which will be send by jqGrid automatically in two parts and you will have on the server all information which you need. In the case you can reduce the number of columns in your grid. You should take in the consideration, that HTML code of grid contain <td> elements for all hidden columns. The <td> elements has style="display:none;" and so are invisable, but there take a little additional memory.
Best regards
Oleg
00:52

05/05/2011

As I wrote composite key components are text strings. They can contain any characters including spaces and _ characters. Due to jqGrid bug spaces and maybe some other characters are not allowed in ids. Total lenght of keys can exceed browser URL limit so maybe urls cannot constructed, probably POST should used.
Where to find sample jqGrid setup which allows to delete row in table where composite primary key contains any characters and can be larger than allowed browser url size ?
10:41

10/08/2009

First of all I suggesed you 4 implementation ways. If you have problem with one or another way you can use other ways. The way with serializeDelData is the simplest one and it will work without any problem.
Second, if you have general data as _id1 and _id2 which can contain any characters there are many simple transformation like base64 which allow you to convert it to less general character set. After the transformation you can use (id1 + '_' + id2) to produce the composed key.
Third, I find that having long strings which contains any characters as the primary key is not the best design solution. If you can make changes in the database model I would recommend you to change the design of the tables. You can add new column with autoincrement integer value and make the column as the new primary key. To be sure that "the old" primary key stay unique you can add UNIQUE constraint to the column. All this is a very simple trick used frequently in the database design. In the way you will have simple integer prinary key.
Best regards
Oleg
12:36

05/05/2011

Will serializeDelData, delData work also in row edit mode ? They are documented in form editing chapter so I expected that they will not work in row editing mode.
URL limit may be too short so onClickSubmit cannot used. Db structure change requires lot of changes in existing application, it is too expensive.
So only way seems to use base64 to create id1_id2 as id for jqGrid and use POST.
Will jqQrid form and row editing modes work OK if id1_id2 key used as id is several kilobytes long ?
Andrus.
12:54

10/08/2009

Hello Andrus,
I suppose that under row edit mode you mean inline editing mode. It has serializeRowData which lay the same role as serializeDelData for the form editing. If you use both editing modes together in the grid you can share the code of the function which implement seriaization in both cases.
I am sure, that if you use id which is several kilobytes long than you should make modification in your database model. The usage of such "key" is almost the same as to use the full row data. It will be slow and ineffective. The sooner you make changes in the tables the better for your application.
If you will replace the keys with "several kilobytes" to the integer key you will save the sending to the client and from the client the garbage which is now inside of '_id1' and '_id2' columns. The searching by key will be also improved.
I don't play with "keys" having several kilobytes. You can test yourself whether it work or not.
Best regards
Oleg
13:15

05/05/2011

This is dictionary table contianing different languages in columns. Primary key is phrase in source language. This table is used for translations. Surrogate id will be used then only by jqGrid.
I'm not sure that adding surrogate id to this table is reasonable for this.
Base64 encoding makes id too long and unreadable in packet dumps when debugging.
How to create encoder/decoder which masks only characters which are not allowed in jqGrid ids? Where to find list of such characters ? Are most unicode characters allowed in ids ? Should only spaces encoded or other characters also ?
In this case ids are shorter and readable.
14:15

10/08/2009

The dictionary tables use typically MD5 hash as the key insead of the full phrase in source language.
I don't understand how you implement packet dumps and why you have the requirements at all. The Fiddler tool for example has "Encoder" button which allows you in easy way to decode any the information from the packet it it is encoded in some standard encoded formats (inclusive Base64 of course).
It seems to me that our discussion goes in the direction which is far from the subject of the forum. I suppose, that you understand my opinion, but you will have to solve your problems yourself.
Best regards
Oleg
12:59

05/05/2011

I created method below to encode/decode jquery ids. This will also handle the case if id is empty. Will thoser methods encode all characters which are not alowed in jquery ids?
Is it resonable to use those methods instead on md5 or base64 ?
/// <summary>
/// Encodes primary key to jqGrid id
/// </summary>
/// <returns></returns>
public string EncodeId(object[] primaryKeyValue)
{
string result = "";
foreach (var key in primaryKeyValue)
{
if (result.Length != 0)
result += "/";
result += Server.UrlEncode(key.ToString());
}
if (result.Length == 0) // empty string used as primary key
return ":";
return result;
}
/// <summary>
/// Decodes jqGrid primary key to actual primary key values
/// </summary>
/// <param name="id">id passed from jqGrid</param>
/// <returns></returns>
public IList<string> DecodeId(string id)
{
if (id == ":")
return new string[] { "" };
var res = new List<string>();
foreach (var key in id.Split('/'))
res.Add(Server.UrlDecode(key));
return res;
}
12:25

10/08/2009

I find encoding of large texts not the best way. With respect of Encoding.UTF8.GetBytes or Encoding.ASCII.GetBytes you can get byte representation of any string and with respect of MD5CryptoServiceProvider.ComputeHash you can calculate the MD5 from the bytes. Then you can convert the MD5 value to HEX or to Base64. In the database you can save the MD5 directly as binary and in HTML use the values converted to HEX or to Base64. So instead of the usage long (even encoded) texts as id you can use short values.
Regards
Oleg
Most Users Ever Online: 715
Currently Online:
65 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66