Issue with AngularJS Datatable remaining unaltered after interaction with modal form

Currently, I am utilizing ASP.NET Boilerplate to develop a Single Page Application (SPA) CRUD application that integrates AngularJS and AngularJS Datatable. A peculiar issue arises when I try to add a new User using ngDialog; although the user is successfully added and stored in the users array, the datatable fails to update accordingly.

AngularJS Controller

angular.module('app').controller('AdminUsersController', [
    '$scope', 'abp.services.app.user', '$modal',
    function ($scope, userService, $modal) {
        var vm = this;

        vm.users = [];
        vm.user = {};

        function fillTable() {
            userService.getUsers({
            }).success(function (result) {
                vm.users = result.items;
                console.log(vm); // User is added to vm.users after vm.save function but table is not updated (only after refresh).
            });
        }
        fillTable();

        vm.deleteUser = function (id) {
            userService.deleteUser({
                id: id
            }).success(function () {
                abp.notify.success('User has been deleted!');
                fillTable(); // Works, table gets updated
            });
        }

        vm.openCreateUserModal = function () {
            $scope.$modalInstance = $modal.open({
                scope: $scope,
                templateUrl: '~/App/views/admin/users/create.cshtml'
            });
        };

        vm.close = function ($event) {
            $scope.$modalInstance.close();
        }

        vm.save = function () {
            userService.createUser(vm.user).success(function () {
                $scope.$modalInstance.close();
                abp.notify.success('User <b>' + vm.user.userName + '</b> has been created!');
                fillTable();
            }).error(function (error) {
                // error handling
            });
        }
    }
]);

AngularJS View:

<div ng-controller="AdminUsersController as vm" ng-app="app">
    <table datatable="ng" class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>Name</th>
                <th>Surname</th>
                <th>Username</th>
                <th>Email</th>
                <th>Creation Date</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="user in vm.users">
                <td>{{user.name}}</td>
                <td>{{user.surname}}</td>
                <td>{{user.username}}</td>
                <td>{{user.emailAddress}}</td>
                <td>{{user.creationTime}}</td>
                <td class="options">
                    <i class="fa fa-pencil"></i>
                    <i class="fa fa-times" ng-click="vm.deleteUser(user.id)"></i>
                </td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Surname</th>
                <th>Username</th>
                <th>Email</th>
                <th>Creation Date</th>
                <th></th>
            </tr>
        </tfoot>
    </table>
</div>

In an attempt to resolve this issue, I experimented with the $apply function but encountered an error stating "At any point in time there can be only one $digest or $apply operation in progress."

Answer №1

ProApp.controller('F1Controller',['$scope' , function ($scope, AppService) { $scope.divItem = false;

var key;
$scope.editItem = function (item,indx) {

    key = indx;

    $scope.item_id = item.budget_item_id;
    $scope.item_discription = item.budget_item_discription;
    $scope.item_quantity = item.budget_item_quantity;
    $scope.item_unit = item.budget_item_unit;
    $scope.item_rate = item.budget_item_rate;
    $scope.item_discount = item.budget_item_discount; 
    $scope.Action = "Update";
    $scope.divItem = true;
}, function () {
    alert('An error occurred while retrieving item records');
    //});
}

$scope.AddNew = function () {

    budget_item_quantity: $scope.item_quantity, 
    $scope.item_id,
    $scope.item_discription = '';
    $scope.item_quantity = '';
    $scope.item_unit = '';
    $scope.item_rate = '';
    $scope.item_discount = '';
};

$scope.AddUpdateItem = function (item_id, item_discription, item_quantity, item_unit, item_rate, item_discount) {

    var getItemAction = $scope.Action;

    if (getItemAction == "Update") {

        $scope.AddRecord[key].budget_item_id = item_id;
        $scope.AddRecord[key].budget_item_discription = item_discription;
        $scope.AddRecord[key].budget_item_quantity = item_quantity;
        $scope.AddRecord[key].budget_item_unit = item_unit;
        $scope.AddRecord[key].budget_item_rate = item_rate;
        $scope.AddRecord[key].budget_item_discount = item_discount; 

        $scope.divItem = false; 
        ClearFields();
    } else
    {
        var item = { 'budget_item_id': $scope.item_id, 'budget_item_discription': $scope.item_discription, 'budget_item_quantity': $scope.item_quantity, 'budget_item_unit': $scope.item_unit, 'budget_item_rate': $scope.item_rate, 'budget_item_discount': $scope.item_discount };
        $scope.AddRecord.push(item);

        ProApp.addItem(item);//call service to send data to server
        ClearFields();


    }
    }


    $scope.AddItemDiv = function () {
        ClearFields();
        $scope.Action = "Add";
        $scope.divItem = true;
    }


    $scope.deleteItem = function (item_id) {
        $scope.AddRecord.splice(item_id, 1);
    };


    $scope.AddRecord = [];


    $scope.Cancel = function () {
        $scope.divItem = false;
    };

    function ClearFields() {
        $scope.item_id = "";
        $scope.item_discription = "";
        $scope.item_quantity = "";
        $scope.item_unit = "";
        $scope.item_rate = "";
        $scope.item_discount ="";

    }



}]);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When attempting to remove an object from an array in Vue.js, an error may occur stating that the property of the

In my project, I am working with 3 files: App, BlogList, BlogItem. The goal is to enable users to delete a post if they choose to. However, when using splice method, I encountered the following error: The property or method "removePost" is not defined o ...

Issue in Jhipster v2.20.0: Production mode causing static pictures to fail loading

I successfully launched a JHipster (v2.20.0) application in production mode. Within the AngularJS code, I have included the following line: img.src = assets/.../mypicture.png. When testing locally, the picture loads correctly. However, in production mode ...

Is the checkbox automatically selected if a property is specified?

I am completely frustrated by this problem. I am struggling to find a way to toggle a checkbox using JavaScript. Here is the HTML code snippet in question: <div class="form-group"> <label class="col-sm-3 control-label"></label> < ...

What is the best way to extract the text inside a div element based on the input value in a

I attempted to extract the innerText of a div along with the input values within it. For instance: <div> My name is Shubham, I work for <input type="text"/> for the last 5 years.</div> My objective is to retrieve all the text ...

Switching the custom cursor depending on the operating system

I am faced with a challenge of customizing the cursor for my application. The issue is that cursors appear differently in OSX compared to Windows; black in OSX and white in Windows. I am considering creating two different cursors, one in white and one in ...

What is the Typescript definition of a module that acts as a function and includes namespaces?

I'm currently working on creating a *.d.ts file for the react-grid-layout library. The library's index.js file reveals that it exports a function - ReactGridLayout, which is a subclass of React.Component: // react-grid-layout/index.js module.exp ...

The module myApp was not successfully instantiated, despite having been declared

Can someone help me troubleshoot my jsfiddle code? Any suggestions or recommendations are welcome! Check out the JSFiddle here. <div ng-app="myApp"> <points></points> <script type="text/ng-template" id="pointstemplate"> ...

Tips for updating an HTML document with information from a JSON file

A json file has been provided with the following details: { "subject":"CSE", "semester":"Fall", "number":"219", "year":"2017", "title":"Title", "instructor_name":"Instructor Name", "instructor_home":"Instructor Home", "expo ...

Issues with navigation drawer not functioning

function adjustMenu() { var navigation = document.getElementById("myTopnav"); if (navigation.className === "topnav") { navigation.className += " responsive"; } else { navigation.className = "topnav"; } } body {margin:0;} ul ...

What is the best way to allow my limit to be as greedy as possible?

I'm facing an issue with the code below where it currently only matches MN. How can I modify it to also match KDMN? var str = ' New York Stock Exchange (NYSE) under the symbol "KDMN."'; var patt = new RegExp("symbol.+([ ...

A guide on extracting XML elements containing periods using JavaScript/extJS

Issue with Dot in XML Tag I am encountering a problem with tags in an XML file I am working on. The issue arises from the presence of dots within the tags, such as <tag.state> and </tag.state>. Unfortunately, JavaScript (specifically extJS) d ...

Is there a way to insert json data into a form input field using jQuery?

I am attempting to insert the JSON result into an input as the value. This is the code I am using: $.ajax({ type:"POST", url: '{% url "url_searchTour"%}', data: data1, success: function(jsonAjaxResult){ console.log(J ...

What is the best way to utilize props and mounted() in NuxtJS together?

I'm a beginner with NuxtJS and I'm looking to implement window.addEventListener on a specific component within my page. However, I also need to ensure that the event is removed when the page changes. In React, I would typically approach this as ...

Unable to transfer Vue.js components in and out of the project

I have a directory structured like this. VueTree components Classic.vue Modern.vue index.js The Classic and Modern components consist of a template, export default {}, and a style. I am importing both of them in index.js as: import Classic ...

Is there a method to have JavaScript display all the information during a SQL while loop?

I'm currently working on implementing a timer for my script. However, I am facing an issue where the timer only counts down from the last result instead of each individual result returned from the query. Any assistance with resolving this problem woul ...

How to store data retrieved with $http.get in AngularJS into a variable

I am attempting to assign data retrieved from $http.get to a variable in my controller. $http.get(URL).success(function (data) { $scope.results = data; console.log('results within $http.get :'+ $scope.results); }); console.lo ...

Using jQuery to target adjacent elements excluding those that are separated by other text

I have been attempting to locate and combine adjacent em tags within paragraphs, but it has proven to be a more challenging task than I initially anticipated. Let's explore some examples to illustrate this issue: <p><em>Hello</em>&l ...

Can the target for orbit controls be set by clicking the mouse?

In my attempt to configure the orbit controls target in three.js, I encounter a challenge. For instance, when using , the camera consistently revolves around the center of the model unless the camera is panned. The desired behavior from the orbit controls ...

Leveraging the Html Extension feature in conjunction with ActionLink

A custom MVC5 Html extension has been created to check if a button displayed on the screen is disabled. Here is the code for the extension: public static HtmlString IsButtonEnabled(this HtmlHelper html, bool buttonEnabled) { return new HtmlString(butto ...

Ionic's concealment feature fails to function properly for animations

I recently started learning about the Ionic framework and I'm attempting to incorporate a fade animation on a 'card' element using CSS. However, despite setting a 1-second transition duration, the targeted element simply disappears after a b ...