The grid option does not seem to be properly populated with the data coming from the

Recently delving into the world of angularjs, I embarked on a mission to populate a ui grid with data sourced from a database. Despite numerous searches for similar issues online, none seem to align with my specific problem. The table displays perfectly fine, yet the data fails to populate. Upon inspecting the developer tools in Chrome under Source, it seems that the Json object is correctly formatted, but alas, nothing appears in the table. It's probably just a minor oversight on my end, so any guidance or assistance would be greatly appreciated.

Below showcases my controller js:

var app = angular.module('skill', ["ui.grid",
                                "ui.grid.edit",
                                "ui.grid.selection",
                                "ui.grid.pagination",
                                "ui.grid.exporter",
                                "ui.grid.cellNav"]);
app.controller('SkillEntryController', function ($scope, $http, $interval,   uiGridConstants, SkillService) {
$scope.data = [];
SkillService.GetSkills().then(function (d) {
    $scope.data = d.data;
}, function () {
    alert('Failed');
});
$scope.columns = [
        { name: "SkillName", displayName: "Skill Code", minWidth: 150, width: "33%"  },
        { name: "Category", minWidth: 150, width: "33%" },
        { name: "Description", minWidth: 150, width: "33%" }
];
$scope.gridOptions = {
    enableSorting: true,
    enableRowSelection: true,
    enableCellEditOnFocus: true,
    exporterHeaderFilterUseName: true,
    treeRowHeaderAlwaysVisible: false,
    paginationPageSizes: [25, 50, 75],
    paginationPageSize: 25,
    columnDefs: $scope.columns,
    data: $scope.data,
    onRegisterApi: function (gridApi) {
        $scope.gridApi = gridApi;
    }
};
}).factory('SkillService', function ($http) {
var fac = {}
fac.GetSkills = function () {
    return $http.get('/Skills/GetSkills');
}
return fac;
});

This snippet depicts my factory method:

public JsonResult GetSkills()
    {
        List<Skill> c = new List<Skill>();
        return new JsonResult { Data = c.Select(x => new { x.Category, x.Description, x.SkillCodeID, x.SkillName }), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    }

Lastly, here is my cshtml file:

@model IEnumerable<SkillResourceCenterApp.Models.Skill>
@using Newtonsoft.Json;
@{
    ViewData["Title"] = "Add Skill";
}
@section scripts{
    <link href="~/Content/ui-grid.css" rel="stylesheet" />
    <script src="~/Scripts/angular.js"></script>
    <script src="~/Scripts/ui-grid.js"></script>
    <script src="~/Scripts/Controller/skill-entry-controller.js"></script>

}

<style>
    .ui-grid-cell.cell-center {
        text-align: center;
    }

    .ui-grid-cell.cell-right {
        text-align: right;
    }
    .no-rows {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.4);
    }

    .no-rows .msg {
        opacity: 1;
        position: absolute;
        top: 30%;
        left: 33%;
        width: 30%;
        height: 25%;
        line-height: 200%;
        background-color: #eee;
        border-radius: 4px;
        border: 1px solid #555;
        text-align: center;
        font-size: 24px;
        display: table;
    }

    .no-rows .msg span {
        display: table-cell;
        vertical-align: middle;
    }


</style>

<h3>@ViewData["Title"]</h3>

<p>
    @Html.ActionLink("Create New", "Create")
</p>


<div class="container-fluid" ng-app="skill" ng-controller="SkillEntryController">

    <div class="row">
        <button type="button" ng-click="addNewRow()" class="btn btn-default col-sm-3 col-md-2">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Row
        </button>
        <button type="button" ng-click="deleteSelected()" class="btn btn-default col-sm-3 col-md-2">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete Selected
        </button>
        <button type="button" ng-click="exportToCSV()" class="btn btn-default col-sm-3 col-md-2">
            <span class="glyphicon glyphicon-download" aria-hidden="true"></span> Export to Excel
        </button>
        <button type="button" ng-click="save()" class="btn btn-primary col-md-offset-4 pull-right col-sm-2">
            Save
        </button>
    </div>
    <div class="row">
        <div class="grid" ui-grid="gridOptions"
             ui-grid-pagination
             ui-grid-selection
             ui-grid-edit
             ui-grid-exporter
             ui-grid-cellNav
             style="height: 500px;">
            <div class="no-rows" ng-show="!gridOptions.data.length">
                <div class="msg">
                    <span>No Results</span>
                </div>
            </div>
        </div>
    </div>
</div>

Answer №1

Ensure that you include the correct field definition within the columnDefs section of your code. For more information, refer to https://github.com/angular-ui/ui-grid/wiki/Defining-columns

var columnDefs: [{
    field: 'foo',
    displayName: 'my foo',
    visible: true,
    maxWidth: 90,
    enableColumnResizing: false,
    cellTemplate: "<div>{{row.entity.foo}}</div>"
}];

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

The scrolling function halts as soon as the element that was middle-clicked is deleted from the

I am knee-deep in developing my own React virtualization feature and encountering a minor annoyance. When I middle click on an item in the list and start scrolling, the scrolling stops once that item is removed from the DOM. My initial thought was that the ...

Launching a Bootstrap modal in Portrait mode through JavaScript

Is there a way to trigger the opening of a modal when the screen is in "Portrait" orientation and hide it when the screen is in "Landscape" orientation? I have tried implementing this functionality, but it seems to not work properly when the page initiall ...

Tips for reducing the size of the sidebar when navigating to a specific page

I have a sidebar that I want to minimize when the user enters the index page. There is a button in the sidebar for that: <a class="mobile-menu" id="mobile-collapse" href="javascript:"><span></a> How can I au ...

When dynamically loading content with ajax, dynamic content fails to function properly

Currently, I am attempting to incorporate dynamic content loading after the user logs in by utilizing $.ajax. Here is how it's being done: $.ajax({ url: "functions.php", type: "GET", data: login_info, datatype: 'html', a ...

Exploring the universal scope in NodeJS Express for each request

I am working with a basic express server that is in need of storing global variables during request handling. Specifically, each request involves multiple operations that require information to be stored in a variable like global.transaction[]. However, u ...

What is causing my website to refresh before I can save the edits I have made after clicking on the edit button

My website is fairly simple, allowing users to add blog posts with a title, author, and content. Each post has two buttons - one for deleting and one for editing. These actions add, delete, or edit the chosen posts within a .json file through a local json ...

How come ng-repeat isn't recognizing the function in the parent scope?

What is the reason for needing to use e in $parent.parentScopeFunc() rather than just e in parentScopeFunc() when {{ parentScopeValue }} works perfectly fine for showing parent scope members in a template? ...

Eliminate the final two digits from each element in the array if they exceed two digits

A challenge I am facing involves an array with multiple elements. My goal is to remove the last two digits from any element in the array that consists of 3 or 4 digits, while leaving elements with 1 or 2 digits unchanged. var test =[ 2, 45,567, 3, 6754]; ...

Error 500 occurred when attempting to access an external PHP file

I am currently utilizing WP Web Scraper version 3.2. When I place the shortcode or template tag (php code) directly into my page, the plugin functions correctly and displays the values. However, when I attempt to include the template tag in an external php ...

Detect a modification event on a field lacking an ID using jQuery

I'm currently facing some challenges with jQuery and I really need to overcome them in order to complete the code I'm working on. The issue is that I can control the img tag, but unfortunately, I am unable to assign an ID to the input tag as des ...

Invoke the API and display the data once the states have been successfully updated

Upon initialization, the code checks the current role of the user. If the role is admin, the setAdmin(true) function is called to set the state of admin to true. By default, the admin state is set to false. When the component is rendered, it initially di ...

Develop a design utilizing a foundational database entity

I'm new to AngularJS and I am seeking guidance on how to properly separate the model from the controller. In my previous experience, I have always integrated models within the controllers. For example: angular.module("app").controller("customerContr ...

Change the image size as you scroll through the window

While my opacity style is triggered when the page is scrolled down, I am facing an issue with my transform scale not working as expected. Any suggestions on how to troubleshoot this or any missing pieces in my code? Codepen: https://codepen.io/anon/pen/wy ...

To interact with the href attribute of an image element in C# Webdriver, simply click on the

Hey all, I recently began exploring web driver with C# and am currently stuck on locating a specific image element to interact with. The HTML snippet for the element in question is provided below. Any assistance would be greatly appreciated. Thanks! < ...

Discovering distinct colors for this loading dots script

Looking for assistance with a 10 loading dots animation script. I'm trying to customize the color of each dot individually, but when I create separate divs for each dot and control their colors in CSS, it causes issues with the animation. If anyone ...

Removing Discord Channel with Discord.js

Currently in the process of developing a ticket system using discord.js Experiencing a challenge where upon a member reacting to the message with a specific emoji, the ticket is supposed to close. However, when running the code, it is throwing an error. i ...

Animated dropdown feature spanning the entire width of the screen

I successfully developed a basic dropdown menu with full-width sub-menu functionality. Check it out on jsFiddle: $(document).ready(function(){ $(".drop").hide(); $(".link-1").mouseenter(function(){ $('.link-1-drop').slide ...

What are the best methods for obtaining live data for my web application?

In my current project, I have developed an HTML5 web application that displays various icons on Google Maps. The front-end is built with AngularJS and JavaScript, while the backend consists of a WebAPI, Entity Framework, and SQL database. At the moment, t ...

Fitting Bounds in Angular with Google Maps

Can anyone help me with calling the fitBounds() method from an angular-google-maps instance? I'm struggling to figure out how to do it after uiGmapGoogleMapApi resolves. In the vanilla js implementation, you can use map.fitBounds(bounds), but I'm ...

What could be the reason behind my inability to initiate this PHP file through jQuery/AJAX?

I'm experiencing an issue with a piece of PHP code (located at ../wp-content/plugins/freework/fw-freework.php). <div id="new-concept-form"> <form method="post" action="../wp-admin/admin.php?page=FreeWorkSlug" class="form-inline" role ...