3

I'm using jqGrid 3.8.2 on ASP.net and I'm declaring a pretty simple jqGrid configuration. The data is showing correctly and I'm able to search by multiple conditions through the search dialog... no problem.

The problem is that in the cases where I'm searching for a value that is not a string I need to now the type of the data on that column. Although I have an 'stype' option on the columns to say exactly the type I'm expecting there, this configuration isn't being passed on the request querystring when I perform a search.

The json I'm getting on the request for 2 search conditions is this: {"groupOp":"AND","rules":[{"field":"EntityID","op":"gt","data":"3"},{"field":"EntityID","op":"lt","data":"8"}]}

Notice that the 'data' value is always enclosed in quotes but the value is numeric and that column have the stype set to 'int' (I can't find anything on how to use this)

Bottom line is that I when I do the request I have no way of passing the information about the type of the column.

How can it be done?

Here's my grid declaration:

    $('#EntityListGrid').jqGrid({
        url: 'my url',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['ID', 'Name', 'Actions'],
        colModel: [
        { name: 'EntityID', index: 'EntityID', width: 50, align: 'left', resizable: true, sortable: true, stype: 'int' },
        { name: 'Name', index: 'Name', width: 250, align: 'left', resizable: true, sortable: true, stype: 'string' },
        { name: 'act', index: 'act', width: 75, sortable: false },
        ],
        pager: $('#EntityListGridPager'),
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: 'EntityID',
        sortorder: 'desc',
        viewrecords: true,
        imgpath: '',
        caption: 'Entities',
        width: EntityListGridWidth,
        height: 400,
        gridComplete: function () {
            var ids = jQuery("#EntityListGrid").jqGrid('getDataIDs');
            var editImageUrl = 'edititem.GIF';
            for (var i = 0; i < ids.length; i++) {
                var cl = ids[i];

                ce = "<img src='" + editImageUrl + "'  onclick='EditEntity(" + cl + "); return false;' />";
                ce2 = "<input type='button' value='details' src='" + editImageUrl + "' onclick='EditEntity(" + cl + "); return false;' />";
                //jQuery("#EntityListGrid").jqGrid('setRowData', ids[i], { act: ce2 });
                $("#EntityListGrid").setRowData(ids[i], { act: ce2 });
            }
        }
        //});
    }).navGrid('#EntityListGridPager', { search: true, edit: false, add: false, del: false, searchtext: "Search" }, {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });
AlexCode
  • 4,055
  • 4
  • 33
  • 46

1 Answers1

3

How you can read in the documentation stype support only two values: "text" and "select". The stype will be used only to build different controls in the searching dialog.

All "data" elements wich will be sent to the server are encoded always as strings and the server have to convert the data to the corresponding data type. For example if you use column as the date or integer the server is responsible to convert the data to DateTime, Int32, Int64, Double or some other type.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, but how can the server know the type to convert to? I know that usually it could just because the request handler has that kind of knowledge but in my case I have a generic search mechanism that needs to know the type to convert each search value, otherwise everything will go as string. – AlexCode Feb 02 '11 at 22:31
  • @AlexCode: The server from the 'my url' have to know full information where to get the data needed for the corresponding jqGrid. If you use internally any "generic search mechanism" you should call the "specific" server method which know the "specific" grid and all types needed. The "specific" server method can make the type conversion and call your "generic search mechanism". – Oleg Feb 02 '11 at 22:43
  • Yeah... maybe the way will be adding knowledge to the handler before calling the generic search engine. Thanks Oleg. – AlexCode Feb 02 '11 at 23:21
  • 1
    @AlexCode: If you have no other way on the server side you can send additional information with respect of `postData` parameters. The data are absolutely free and the data will be send as a part of any requests to the server. You can for example post the information about the types of all column which you use. – Oleg Feb 02 '11 at 23:29
  • That can also be a good idea. I'm running through this issue just because I want to keep my layers completely decoupled. I'm doing this in ASP.net Webforms, so I have the jqGrid on the page that calls an ASHX that will digest the request and call a WCF Service that is the sole responsible for the CRUD. On the service is where I have the generic Search method that is used in other places as well. I could create a specific method on the service for the grid but I'm trying not to for the sake of WCF Service code maintenance. Lets see what I can do with that postData idea. – AlexCode Feb 02 '11 at 23:43