开发者

how to delete multiples rows in jqgrid if the method selarrrow returns arrays that has more than 1 index?

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>
&开发者_运维知识库lt;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 {
                    }
                });
            }
        });
    });
});


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.


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


  1. multiselect: true,

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜