在插入时从网格隐藏项目

时间:2018-07-25 13:15:36

标签: ajax jsgrid

我想知道您是否可以帮助我解决以下问题。 我有两个关于电子邮件的案例。有些可能是好的,有些则是错误的。

所以我有一个在ajax中调用的函数来获取数组中的数据。在更新元素时​​,我已经成功隐藏或删除了项目,但在插入时无法复制它。

这是我的代码:

onItemUpdating: function (args) {
                    $.ajax({
                        url: Routing.generate('admin_participant_update', {'id': args.item.bloomin_mu_id}),
                        data: {'new_data': args.item},
                        type: 'PUT',
                        async: false,
                        success: function (response) {
                            console.log(response);
                            let grid = $('#jsGrid');
                            let row = grid.jsGrid('rowByItem', args.item);
                            let rejectedEmails = $('#rejectedEmails');

                            if (response.valid === 'INVALID_EMAIL'  && !rejectedEmails.hasClass('active')) {
                                if (rejectedEmails.hasClass('active'))     {
                                    grid.data("JSGrid").data.splice(row, 1);
                                }
                                toastr['warning']('Adresse Email incorrecte !');
                            }

                            if (response.valid === 'VALID_EMAIL' && rejectedEmails.hasClass('active')) {
                                grid.data("JSGrid").data.splice(row, 1);
                                toastr.success('Adresse email valide');
                            }
                            grid.jsGrid('refresh');
                        }
                    }).fail(function (data) {
                        args.cancel = true;
                        console.log(data);
                        alert("Can't update participant. Reason: " + data.responseJSON.error);
                        console.error('Unable to update participant.');
                        console.error(data);
                    });
                },

我试图在插入时重现它:

onItemInserting: function (args) {
                    console.log(args);
                    $.ajax({
                        url: Routing.generate('admin_participant_create', {'ml_id': {{ listId }} }),
                        data: {'new_data': args.item},
                        type: 'POST',
                        async: false,
                    }).success(function (data) {
                        let grid = $('#jsGrid');
                        let row = grid.jsGrid('rowByItem', args.item);
                        if (data.valid === 'INVALID_EMAIL' && !$('#rejectedEmails').hasClass('active')) {
                            grid.data("JSGrid").data.splice(row, 1);
                        }
                        toastr['warning']('Adresse Email incorrecte !');
                        $('#jsGrid').jsGrid('refresh');
                    }).fail(function (data) {
                        args.cancel = true;
                        alert("Can't create participant. Reason: " + data.responseJSON.error);
                        console.error('Unable to create participant.');
                        console.error(data);
                    });
                },

并且“删除”了一行,但只有第一行。错误的输入仍然在网格中!

在回调“ onItemInserted”中刷新了网格。

感谢您的帮助

0 个答案:

没有答案
相关问题