Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k 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 Reply

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...