0

Here is a fragment of my grid js:

$grid.jqGrid({
        url:'xtras/Products.php',
        editurl:'xtras/Products.php',
        datatype: "json",
        mtype:'GET',
        colModel:[...
            {name:'ID',index:'catalogue.ID', hidden:true, width:10, sortable:false, editable:true, key:true},
            ....]

and PHP side:

elseif ($_REQUEST["oper"] == "del") {

        $deleteSQL = sprintf("delete from snapper.catalogue where `catalogue`.`ID` = %s",
                        GetSQLValueString($_REQUEST['ID'], "int")
                    );

        $Result = mysqli_query($GLOBALS["___mysqli_ston"],$deleteSQL) or die($error = mysqli_error($GLOBALS["___mysqli_ston"]));
}

where $_REQUEST['ID'] not passed to $_REQUEST["oper"] == "del", however it does pass to $_REQUEST["oper"] == "edit"

EDIT dump:

_REQUEST - 2015-11-25 12:59:53: 
Array
(
    [Catalogue] => test523
    [Artist] => STEPHANE GRAPPELLI
    [Title] => kkk1651564
    [UKDP] => 5.50
    [Release_Date] => 25 Nov 15
    [Ppoint] => 1
    [Label] => 2
    [Format] => 33
    [Genre] => 27
    [UPCEAN] => 636551052375
    [AlbumCLineYear] => 0
    [AlbumCLineInfo] => 
    [AlbumPLineYear] => 0
    [AlbumPLineInfo] => 
    [Credits] => 
    [Artist_Sort] => 
    [Active] => 1
    [Deleted] => 1
    [id] => 1951
    [copyID] => 
    [oper] => edit
)

DEL dump:

_REQUEST - 2015-11-25 13:00:49: 
Array
(
    [oper] => del
    [id] => 4
)

where [id] is row number in the grid, not ID in the database. Why?

Elen
  • 2,345
  • 3
  • 24
  • 47

1 Answers1

2

Probably you should add prmNames: { id: "ID" } option of jqGrid if you want that the name of id parameter in the data posted during Edit/Delete will be ID instead of id? By the way using the option you can remove unneeded hidden ID column from colModel.

If you do need to hold hidden column ID and need that jqGrid send both id and ID to the server then you should add editrules: { edithidden: true }, hidedlg: true properties to the definition of ID column. See the old answer.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Oleg! long time. I actually thought of this and tried to use both id and ID - same result - EDIT works, DELETE doesn't. Just tried `prmNames` - it didn't work either =( it still passes row num in grid Array ( [oper] => del [ID] => 2 ) I added `editrules: { edithidden: true }, hidedlg: true` id `key:` `true` and `false` - didn't work... – Elen Nov 25 '15 at 12:43
  • 1
    @Elen: I'm not sure which **specific** problem could exist in [Guriddo jqGrid 5.0.1](http://guriddo.net/?page_id=103334) which you use. You can try to modify (at least temporary) URLs to CSS and JS files to the URLs of [free jqGrid](https://github.com/free-jqgrid/jqGrid) (the independent fork of jqGrid which I develop since almost one year). See [the wiki](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs) article with URLs. If you would have correct posted data then the problem, which you describe, is really Guriddo bug. If you want use Guriddo then report it. – Oleg Nov 25 '15 at 12:57
  • Oh i didn't realised that. I would prefer the old grid than Gruriddo. Let me look into that. – Elen Nov 25 '15 at 13:03
  • @Elen: The origin was [the post](http://www.trirand.com/blog/?p=1438) where old jqGrid which was provided till 4.7 version under MIT and/or GPLv2 was renamed to Guriddo jqGrid JS, which source code is still opened, but the product need be now purchased see [here](http://guriddo.net/?page_id=103334) the prices. Short after that I made the for of the latest free version 4.7 and continue to develop it [here](https://github.com/free-jqgrid/jqGrid). Many new features, which I implemented are described on [the wiki](https://github.com/free-jqgrid/jqGrid/wiki) and readme to every version. – Oleg Nov 25 '15 at 14:02
  • I see. I didn't know that. I'm just trying your grid but i have problem with subgrids.. content is not loading. can you point me where i can find a guidance to upgrate from `4.4.2` to the 4.10 ? – Elen Nov 25 '15 at 14:20
  • @Elen: I tried to hold the compatibility with old versions. Mostly one could just replace the URLs. New features which I implemented could simplify the code, but old code works in the most cases. Do you tried to use it? Do you have some problems? – Oleg Nov 25 '15 at 15:12
  • yes i just replaced jqgrid.js with `src="//cdnjs.cloudflare...` - it creates grid columns, header and footer, but data is not loaded into it. just showing message "loading" (you helped me to implement subgrids back 2012! http://stackoverflow.com/questions/13530922/jqgrid-open-subgrid-only-if-there-is-some-data) – Elen Nov 25 '15 at 15:22
  • @Elen: I hoped that you included non-minimized `jquery.jqgrid.src.js`. In the case you should open you demo in debugger (for example Developer Tools of IE or Chrome). "loading" means typically some error during processing the data. You will see the exact place of jqGrid code with the values of all variables. If you would have problems to localize the error yourself that you could prepare the demo and send me the link. – Oleg Nov 25 '15 at 15:48
  • Oh of course... it points out to grid definition line `{name:'Sales Text',index:'sales_txt', width:60, sortable:false, edittype: 'text', editable:true, classes: 'red', cellattr: function(rowId, val, rawObject) { if (val.toLowerCase() == 'done'){ return 'style="color: #999"'; } }` - in particular `Cannot read property 'toLowerCase' of null` and this is true - inital data is `null` but didn't cause me problems before – Elen Nov 25 '15 at 15:58
  • 1
    @Elen: You can replace `val.toLowerCase()` to `String(val).toLowerCase()` or to test `if (typeof val === "string" && val.toLowerCase() === 'done') {...` or `if (val == null && val.toLowerCase() === 'done') {...`. **I rewrote many parts of jqGrid code to implement new features.** You old code was unsafe before and now you get `val` as `null` if the input data was `null`. Is your code work after the simple code fixing? – Oleg Nov 25 '15 at 16:06
  • oh wow! it did load data straight away - thank you! but my inline editing don't work as expected. it jumps to the last line in the subgrid instead of the opening the clicked line... but i will post this issue as a separate question. Thanks for your help! you are awesome! – Elen Nov 25 '15 at 16:14
  • @Elen: You are welcome! The best would be if you would debug the code and to post mostly exact description of the problem inclusive the test data (input data). Alternatively you can prepare small demo (in JSFiddle for example) which can be used to reproduce the problem. I will debug the demo and modify it so that it works. – Oleg Nov 25 '15 at 16:20