2

I have my grid with multiselect = true, something likes this, you can click each checkbox and then delete, when I delete my first row I know the method selarrrow creates and arrays It just delete, but when I want to delete the second row It just never do the delRowData method, and when I select multiple checkbox It just delete the first. I think my method is looping over and over againg each time and never delete at least visually the other row, how can I fix it?? any advise thanks

this is my method:

onSelectRow:function(id) {
    $("#mySelect").change(function (){ 
        if(($("#mySelect option:selected").text()) == 'Deleted') {
            var id = $("#list2").getGridParam('selarrrow');
            for(var i =0; i<id.length;i++) {
                $("#list2").jqGrid('delRowData',id[i]);
        }
    });
}

html

</head>
<body>

<div>
            Move to:
            <select id="mySelect">

            <option value="1">Select and option</option>
            <option value="2">Trash</option>
            <option value="3">Deleted</option>

            </select>
</div>

<table id="list2"></table>
<div id="pager2"></div> 
</body>
</html>

js

$("#Inbox").click(function () {
    $.post('../../view/inbox.html', function (data) {
        $('#panelCenter_1_1').html(data);
        $("#list2").jqGrid({
            url: '../..controller/controllerShowInbox.php',
            datatype: 'json',
            colNames: ['From', 'Date', 'Title', 'Message'],
            colModel: [
                { display: 'From', name: 'name', width: 50, sortable: true, align: 'left' },
                { display: 'Date', name: 'date', width: 150, sortable: true, align: 'left' },
                { display: 'Title', name: 'title', width: 150, sortable: true, align: 'left' },
                { display: 'Message', name: 'message', width: 150, sortable: true, align: 'left' },
            ],
            searchitems: [
                { display: 'From', name: 'name' },
                { display: 'Date', name: 'date' },
                { display: 'Title', name: 'title' },
                { display: 'Message', name: 'message' },
            ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pager2',
            sortname: 'id_usuario',
            viewrecords: true,
            sortorder: "desc",
            caption: "Inbox",
            multiselect: true,
            multiboxonly: true,
            onSelectRow: function (id) {
                $("#mySelect").change(function () {
                    if (($("#mySelect option:selected").text()) == 'Trash') {
                        var id = $("#list2").getGridParam('selarrrow');
                        if (id != '') {
                            var grid = $("#list2");
                            grid.trigger("reloadGrid");
                            $.post('../../controller/controllerChangeStatus.php', { id: id }, function (data) {
                                $('#panelCenter_2_1').html(data);
                                grid.trigger("reloadGrid");
                            });
                        }
                    } else if (($("#mySelect option:selected").text()) == 'Deleted') {
                        id = $("#list2").getGridParam('selarrrow');
                        if (id != '') {
                            var grid = $("#list2");
                            grid.trigger("reloadGrid");
                            $.post('../../controller/controllerChangeStatus.php', { id: id }, function (data) {
                                $('#panelCenter_2_1').html(data);
                                grid.trigger("reloadGrid");
                            });
                        }
                    } else {
                    }
                });
            }
        });
    });
});
Oleg
  • 220,925
  • 34
  • 403
  • 798
bentham
  • 1,701
  • 3
  • 20
  • 32
  • any help?? It is just with selarrow – bentham Sep 20 '11 at 17:37
  • The code which you posted still not full: 1) you use selectors "#Inbox", "#panelCenter_1_1" and "#panelCenter_2_1", but the HTML code has no corresponding elements 2) you use `sortname: 'id_usuario'`, but there are no column with the cane 'id_usuario' 3) one needs the data returned from '../../view/inbox.html' 4) one needs data returned from '../..controller/controllerShowInbox.php' 5) the usage of traling commas ("},]") in colModel and searchitems are syntax errors. Could you append your question with full information needed to reproduce your problem? – Oleg Sep 25 '11 at 19:22
  • My code Its too long to post also my languaje is spanish, what about If I send you my project? or any ideas? – bentham Sep 26 '11 at 20:28
  • The problem is that I don't use PHP. I use WFC, ASP.NET MVC or other "Microsoft technologies" on the server side. So it would be better to stay on JSON, HTML and JavaScript. If you open the source code of the page in the web browser you will get the full HTML and JavaScript code. To catch all server responses (JSON and HTML) one can use [Fiddler](http://www.fiddler2.com/fiddler2/) or [Firebug](http://getfirebug.com/). – Oleg Sep 26 '11 at 20:41
  • Thanks for answering really appreciated and what does custom formatter do? – bentham Sep 28 '11 at 03:59
  • With respect of the [custom formatter](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter) you can construct any HTML contain of the cells in the grid column base on the input data. I don't understand how the question is connected with your current question. If you still have the described problem, please post full information needed to reproduce the problem. – Oleg Sep 28 '11 at 08:27

3 Answers3

2

You code looks very strange for me. I can't explain the effects which you describe without having the demo code, but I could point you to some places in the code which should be rewrote.

First problem: you use id parameter in the line onSelectRow:function(id) and then use the same variable name id to declare var id = $("#list2").getGridParam('selarrrow');. I don't understand why you do this. If you don't need parameter of onSelectRow you can just use onSelectRow:function() which will make the code more clear.

Second problems: you use binding to change event in $("#mySelect").change, but you use the statement inside of another event onSelectRow. So on every row selection you will have one more event handler to the change event. For example you would replace the body of $("#mySelect").change(function (){ to alert("changed!"). Then you would select two different rows and change the option in the "#mySelect". You will see two alerts. Then you select another row and change the option in the "#mySelect". You will see three alerts. And so on.

So you should rewrote your code in any way. If you will still have the same problem you should include full demo code (including HTML code with <select id="mySelect">...) which can be used to reproduce your problem.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • hello, I am developing an email, and my inbox is displayed in the jqgrid, then for changing the status I need another event a select, once the user select an option the mail has to be delete, thats what I am trying to do?? what would be your approach? thanks for answering I am having troubles deleting the mails – bentham Sep 22 '11 at 21:06
  • @GeorgeBecj: Could you post some HTML and JavaScript code for better understanding what you do. If is for example possible to implement ` – Oleg Sep 22 '11 at 21:52
  • Thanks for keep answering I already edit the post I hope you can help me thanks again – bentham Sep 23 '11 at 13:56
  • @GeorgeBecj: Sorry, but I don't see any changes in the text of your question. Where you edited the post? – Oleg Sep 28 '11 at 08:24
1

I use a different approach. I build a vector of selected row ids and then process 'em with a single batch statemente server side then reload the grid.

More or less the code is.

var righe = $(nomeGrigliaFiglia).getGridParam("selarrrow");
if ((righe == null) || (righe.length == 0)) {
    return false;
}
var chiavi = [];
for (var i = 0; i < righe.length; i++) {
    var Id = righe[i];
    var data = $(nomeGrigliaFiglia).jqGrid('getRowData', Id);
    // Process your data in here
    chiavi[i] = new Array(2)
    chiavi[i][0] = data.FieldKey;
    chiavi[i][1] = data.FieldChildId;
}

Note that I'm using this to actually send a int [][] to a C# Action

BigMike
  • 6,683
  • 1
  • 23
  • 24
-1
  1. multiselect: true,

  2. in your data process php $SQL .= "DELETE FROM ". $table. " WHERE no in ($_POST[id]);" ;

Daniel
  • 23,129
  • 12
  • 109
  • 154
Josh Sunderman
  • 151
  • 1
  • 2
  • I'm not sure if this answer addresses the question or not, but the code you posted *is* vulnerable to `SQL Injection` attacks. `$_POST`, `$_GET` and `$_REQUEST` should **never** be used directly in an SQL statement. Ever. – Jeremy J Starcher Oct 04 '12 at 20:46