logo
down
shadow

add column headers from array to datatables jquery


add column headers from array to datatables jquery

By : user2951548
Date : November 18 2020, 11:13 AM
may help you . append the header data before initializing the dataTable
FIDDLE
code :
var jsonArray = {"Columns":[{"name":"ID","field":"id"},{"name":"America","field":"america"},{"name":"India","field":"india"},{"name":"China","field":"china"},{"name":"Japan","field":"japan"}]};
var columnArray = jsonArray['Columns'];
var titleArray = [];
$('table thead tr').empty();
for (var j = 0; j < columnArray.length; j++) {
    var parsedJson = $.parseJSON(JSON.stringify(columnArray[j]))
    var mTitles = parsedJson["name"];
    $('table thead tr').append("<th>"+ mTitles +"</th>");
};
$('table').DataTable();
var jsonArray = {"Columns":[{"name":"ID","field":"id"},{"name":"America","field":"america"},{"name":"India","field":"india"},{"name":"China","field":"china"},{"name":"Japan","field":"japan"}]};
var columnArray = jsonArray['Columns'];
var titleArray = [];
for (var j = 0; j < columnArray.length; j++) {
    var temp = {};
    temp['title'] = columnArray[j]["name"];
    titleArray.push(temp);
};
$('table').DataTable({ "columns": titleArray});


Share : facebook icon twitter icon
tag). The second table depends on the selection of a row in the first table. Everything is working, and both tables are loading and displaying data like they should, with the exception of when the second table is empty. , Shooting in the dark. Have you tried:
code :
table {
    table-layout: fixed;
}
With jQuery DataTables, how do I make the mouse cursor change over sortable column headers?

With jQuery DataTables, how do I make the mouse cursor change over sortable column headers?


By : user3463503
Date : March 29 2020, 07:55 AM
hop of those help? I'm not familiar with dataTable() specifically, but the easiest way is to give the sortable columns a class and use the CSS cursor:pointer; property to make the mouse indicate it is clickable.
JQuery Datatables - Empty table column headers are squished

JQuery Datatables - Empty table column headers are squished


By : 郑召召
Date : March 29 2020, 07:55 AM
it helps some times I have a page with two dataTables. One of them is populated with data on page load, the other is empty (but skeletal, i.e. it has headers and empty
How to dynamically change Datatables multiple column headers using ajax and jquery without refreshing the webpage?

How to dynamically change Datatables multiple column headers using ajax and jquery without refreshing the webpage?


By : Victoria Cuellar
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I solved the question by changing the way of initialising table in HTML instead of altering the settings in Datatables.
What I did is: first, remove the existing table, as well as the table wrapper!
code :
 $('#table_id').remove();
 $('#table_id_wrapper').remove();
 var content = "<table id='table_id' class='display datatable' style='width:100%;'><thead>";
 content +='<tr>';


 re = re.substring(0,re.length-1);
 // alert(re);
 var retitle = re.split(",");
    alert (retitle + 'x');
   var c = retitle.length;
   var atarget = [];
   var stitle = [];
   for(var i=0; i<c; i++){
     atarget[i] = i;
     stitle[i] = retitle[i];
     content += '<td>' +retitle[i]  + '</td>';

   }

  content +=' </tr></thead>';
  content +='<tbody></tbody>'
  content += "</table>";
  $('#tab3').append(content);
   var settings = {

     "bPaginate": false,
     "bProcessing": true,
    "bLengthChange": true,
    "bFilter": false,
    "bInfo": false,
    "bAutoWidth":false,
    "bServerSide": true,
    //  "sDom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
     "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
     "sAjaxSource": './aadata.txt',
   "aoColumnDefs": [       
     { "aTargets":atarget}
     ]
   };

 $('#table_id').dataTable().fnDestroy();
 $('#table_id').dataTable(settings);
 $('#table_id').dataTable().fnReloadAjax();
Laravel 5.5 - Create Column Headers for DataTables from JSON Object Array

Laravel 5.5 - Create Column Headers for DataTables from JSON Object Array


By : Sam Trimmer
Date : March 29 2020, 07:55 AM
With these it helps It looks like aoColumns is just an array of objects, so you should be able to loop through your JSON to build it. Something like this maybe:
code :
var json = {{ $json_var_from_controller }},
    aoColumns = [];

for(var key in json[0]) {
    aoColumns.push(
        {"sTitle": key[0].toUpperCase() +  key.slice(1), "mData": key }
    );
}
How to clear all column headers using DataTables

How to clear all column headers using DataTables


By : Brucelee Thanh
Date : March 29 2020, 07:55 AM
help you fix your problem I was wondering, when updating DataTables using AJAX, how do you delete column headers left over from a previous DataTable? I have bDestroy set to true in both of my functions to draw the table, however, one of the tables has fewer columns than the other, and when loading the smaller table after loading the larger one, I get leftover column headers from the larger table. , You need to change on fnDrawCallback like below:
Related Posts Related Posts :
  • Keypress event for ajax call does not work
  • responsive/fluid jQGrid with Twitter Bootstrap
  • IE10 does not seem to fire load event
  • Remove tipTip tool tip
  • jquery datepicker changing unavailable dates in one instance
  • TableTools plugin export buttons are not working
  • Prepopulate jquery token input textbox
  • Open a fancybox link with ajax
  • Getting jQuery and AngularJS content assist / auto-complete in eclipse for standalone HTML "file"
  • TR alternate background colour with unequal number of TD
  • DATATABLE jQuery TH and TD alignment
  • Jquery UI Convert Select's to Range Slider
  • Change text in text field according to link that has been clicked
  • Animate addClass + removeClass transitions?
  • knockout ajax call data-BIND
  • How do I create a variable with a number based on an element's number position using jquery?
  • Prevent fixed position element from flickering during jQuery animation
  • points are not visible clearly in nvd3 ghaph
  • How to write a regular expression for IP address format
  • Animate 3 DIVs from right to left when page is loading.
  • How to pivot columns in free jqgrid 4.15.4
  • the jquery method works fine but when made as a function not working
  • Show/hide text doesn't work when targeting link within div
  • multiple autocomplete search input fields
  • Display image in cell using Jquery jTable
  • jQuery and Wordpress - Scripts not working
  • flickering when mouse over, .hover() show/hide div(s)
  • Using Django's JSONResponseMixin to respond to AJAX requests
  • Unable to render charts using Wicked PDF
  • Style to dynamically created elements
  • hover not working for items in list
  • Keep server session alive automatically based on activity / input, using JQuery
  • jQuery load() taking a long time
  • Change / Exchange values in textboxes on text change in jquery
  • Unslider arrow code overriding slider options
  • what is the traditional way of sorting search results?
  • Do the action when the DIV comes in the display area of the browser with jQuery
  • jQuery slideshow overlapping CSS ribbon
  • JQuery animate function dont work
  • problems charts jquery highcharts
  • How to reset the select box values in Jquery sumoselect Multi select plugin
  • css absolute position on top of another element
  • How use jQuery String variable in html body
  • Get a row from table in view on modal bootstrap using codeigniter
  • How to make the effect of a div that covers an other div when scrolling?
  • Data binding using a button
  • How do i replace all dot in string to Underscore?
  • grab non-sibling element with jquery
  • Select a word and click it
  • Trigger modal instead redirect to /users/sign_in path, Rails 4 with devise
  • Combining Parent theme JS and CSS
  • Angular ui-grid - DropDown Selection shows Id
  • jquery addclass when there is content on body
  • JQUERY : CSS does not apply to dynamically created elements
  • Bootstrap multiselect dropdown checkbox not working on paginated table
  • JQuery scroll to dynamic id
  • Jquery first time tried ajax
  • Disable the link on the active tab (Bootstrap)
  • How to handle this validation when a div is added?
  • how to show/hide and check/uncheck checkboxes dynamically inside kendo grid
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org