Displaying dynamic data in a data table involves taking an array as input and customizing the fields within that array.
Displaying dynamic data in a data table involves taking an array as input and customizing the fields within that array.
Add a specific class to the <table>
tag that is designated as the data table
Javascript
var ApplyDataTableClass = function (data) {
table = $('.datatable').DataTable({
retrieve: true,
data: data,
columns: [
{ data: 'EmployeeID' },
{ data: 'EmployeeName' },
{ data: 'DOB', type: 'date-dd-mmm-yyyy', targets: 0, width: '100px' },
{ data: 'Salary' },
{ data: 'DepartmentName' },
{ data: 'CountryName' },
{ data: 'StateName' },
{ data: 'CityName' },
{
data: null,
render: function (data, type, row) {
var html = "";
html += '<button class="btn btn-primary" data-viewtype="' + data.EmployeeID + '" id="' + data.EmployeeID + '" title="View"><span class="fa fa-user"></span></button> ';
html += '<button class="btn btn-success" data-edittype="' + data.EmployeeID + '" id="' + data.EmployeeID + '" title="Edit"><span class="fa fa-pencil"></span></button> ';
html += '<button class="btn btn-danger" data-deletetype="' + data.EmployeeID + '" id="' + data.EmployeeID + '" title="Delete"><span class="fa fa-trash"></span></button>';
return html;
}
}
],
});
};
HTML
<table id="table_id" class="datatable datagrid">
<thead>
<tr>
<th>EmployeeID</th>
<th>EmployeeName</th>
<th>DOB</th>
<th>Salary</th>
<th>Department</th>
<th>Country</th>
<th>State</th>
<th>City</th>
<th>Action</th>
</tr>
</thead>
</table>
Imagine I have multiple span elements like this: <span>A</span> <span>B</span> <span>C</span> <span>D</span> and a div element (which will be converted to a button later) named "change". <div id="chan ...
I've created a basic form: <form class="dataform" method="post" id="settings" action="/"> <input type="radio" name="shareSetting" value="n"/> <input type="radio" name="shareSetting" value="y"/> <input type="button" na ...
After reading several examples, I am still struggling with a particular issue. I am receiving a feed from an API that is structured like this: { total:123, id: "1234", results: [ { id: "1234", name: "bobs market", ...
At the same time, I encountered another error stating "Invalid handler for event 'click'". <template> <div id="example-2"> <!-- `greet` is the name of a method defined below --> <button v-on:cli ...
In my layout, I have one column, one row, and three nested columns. Each column contains a custom-designed button instead of using the default Bootstrap button. However, there seems to be an issue where one of the columns is getting cut off. To better und ...
I need to implement text field validation on the keyup event. The text field should only accept money type decimals such as: (12.23) (.23) (0.26) (5.09) (6.00) If any incorrect value is entered, it should revert back to the previous value and remove the ...
Continuing from a previous inquiry regarding the disabling of a submit button until all ajax calls have completed... It appears that individuals are still able to submit the form despite the button being disabled and a warning displayed. This could possib ...
When setting a new style rule for an element, Chrome generates a selector that includes the entire hierarchy of elements instead of just the class name. For instance: <body> <div class="container"> <span class="helper"> ...
Whenever I hover over the #HoverMe div, a hidden #hidden div appears, and when I unhover it, the hidden div disappears again. The #hidden div contains a sub-div that functions like a dropdown list. The #hidden div is styled with position: absolute;. How ca ...
I'm currently developing a simple calculator that increases a variable when a button is clicked, displaying the updated value in a div. Each click on the 'amount-upwards' button adds 200 to the displayed number. Below is the jQuery code I a ...
Currently, I am offering my assistance as a volunteer to develop a fast AngularJS App for a non-profit organization. Although I have successfully set up Angular, the main issue I am encountering has to do with parsing JSON data. The JSON object that I am ...
I'm looking to disable the link for the "parent li" in a dropdown menu when viewed on mobile. Here's the HTML structure: <ul> <li class="parent"></li> <li class="parent"></li> <li class="parent"></li&g ...
I am working with two forms (request and feedback) where I need to use jQuery Ajax to send the data. When a user submits a request, the subject line will display "Request". If they submit feedback, the subject line will display "Feedback". Here is my cur ...
Trying to figure out the best method for moving game characters in my JavaScript game - should I go with window.webkitRequestAnimationFrame or stick with setInterval? Any advice is appreciated! ...
Seems like a simple and common question, right? I also thought so. How can I achieve this in angularJS? CSHTML @using (Html.BeginForm("Order", "Shop", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) { <div class="container" ng-ap ...
I have implemented a custom Segoe UI font in my CSS file. While it displays correctly in Chrome, I am facing an issue where IE and Firefox are showing the default font in certain areas. Below is the snippet of the CSS code: body { margin:0px auto; ...
As a newcomer to Ajax, I am facing an issue with deleting records from the database using Sweet Alert2. Although my swal is working fine, the ajax function seems to be malfunctioning. Can anyone point out where the problem might be and suggest a solution? ...
Whenever I attempt to run this function, I encounter an issue. My goal is to retrieve the latitude and longitude of an address from Google's API. This error message pops up: core.js:15723 ERROR TypeError: Cannot read property 'geometry' of ...
After adding a simple Ajax form to my WordPress website, I encountered an issue where the validation works fine, but instead of sending the email, the form refreshes after submitting. Here is the code snippet: <script type="text/javascript"> jQ ...
At this website, there seems to be an issue with how the footer displays on Internet Explorer and certain older versions of Firefox. However, it appears perfectly fine on Firefox 3.6.13. Any suggestions on what could be causing this discrepancy? ...