0

I want to delete data from multiple checkbox selected I fetch data from ajax request through but I don't know next process.

This is ajax form

<script type="text/javascript">
            $(document).ready(function () {
                $("#MyButton").click(function ()
                {
                    var id = $('#grid').yiiGridView('getSelectedRows');
                    alert(id);
                    $.ajax({
                        type: 'POST',
                        url:'index.php?r=usermaster/multipledelete',
                        data: {id: id},
                        success: function () {
                            $(this).closest('tr').remove();
                        }
                    });
                });
            });
</script>

What exactly I want to delete this multiple data I got id through the ajax form

public function actionMultipledelete($id)
{    
    if (\Yii::$app->request->post()) {
        $keys = \Yii::$app->request->post('id'); // id is array
    }
    if (!empty($keys)) {
        $this->findModel($keys)->delete();
    }
 }
1
  • what error you are getting? Commented Oct 21, 2016 at 4:44

1 Answer 1

1

If you are looking for the action code, this may help you:

public function actionMultipledelete($id)
{
    if (\Yii::$app->request->post()) {
        $keys = \Yii::$app->request->post('id'); // id is array
    }
    if (!empty($keys)) {
        foreach($keys as $id) { 
            $this->findModel($id)->delete();
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

you must use loop for it as $keys will be array
but there is problem delete only one row not deleting selected row by checkbox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.