Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

jquery - Custom delete button in jqGrid

I'd like to implement my own delete functionality in jqGrid. I'm currently using the built-in UI (select row, press trashcan button in footer, confirm) but I'd prefer to have a delete button in each row and implement my own UI for confirmation.

I don't see anything in the API that allows me to fire off a delete to the server - just delRowData, which deletes it on the client. Can this be done?

(I'm using the ASP.NET component, FWIW).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no part of the basic jqGrid component that handles the server side deletion - even if you use the built in delete, its not removing it server side for you, you have to handle that yourself. But here's how to set it up so your script is called when someone clicks your custom delete button:

// your custom button is #bDelete
$("#bDelete").click(function(){ 

    // Get the currently selected row
    toDelete = $("#mygrid").jqGrid('getGridParam','selrow');

    // You'll get a pop-up confirmation dialog, and if you say yes,
    // it will call "delete.php" on your server.
    $("#mygrid").jqGrid(
        'delGridRow',
        toDelete,
          { url: 'delete.php', 
            reloadAfterSubmit:false}
    );
});

The following information is past via POST to your delete URL

Array
(
    [oper] => del
    [id] => 88
)

Where id is obviously the id you passed into the function in this case, the value of toDelete.

I actually just did this for my own project, in response to your question - although I had a vague idea of how to do it before I saw the question. So ... thanks for making me get to it!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...