Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Produse care au fost manufactura ...

WoW Ascension parere

Eliberare fiscal - ajutor

Caut un NVR model HGNVK-48902
 Baterie Macht

Complex termogenic opinii ( Arzat...

Reteta compensata dupa scrisoare ...

aerofoto mapn dji mini 4 pro
 Click inchidere fereastra Win11 e...

Nedumerire produs

Se justifica constructia edificii...

Sfat achizitie masina - drumuri n...
 inceput de drum Uber/Bolt pe SRL

Sticla noua de la Sigma

La multi ani @fiuny!

Ghiocei - nu mai infloresc
 

Probleme cu DataTable

- - - - -
  • Please log in to reply
2 replies to this topic

#1
geotux

geotux

    Junior Member

  • Grup: Junior Members
  • Posts: 49
  • Înscris: 12.07.2019
Salut !

Folosesc DataTable pentru a afisa date dintr-o baza MySql
http://86.127.36.60/...z/spot_1624.php

Dupa ce se selecteaza luna, trebuie sa se schimbe continutul tabelului si graficului.
Valorile se schimba si la tabel si la grafic, doar ca la tabel nu se incarca optiunile(e.g.: limitarea numarului de randuri, chekbox-uri la fiecare rand)

<select class="form-control dropdown" id="dd" name="dd" onchange="selectSpecie()" style="width:200px;margin-left:20px;">
												 <option value="1">January</option>
												 <option value="2">February</option>
												 <option value="3">March</option>
												 <option value="4">April</option>
												 <option value="5">May</option>
												 <option value="8">August</option>
												 <option value="9">September</option>
												 </select>


si functia selectSpecie():

function selectSpecie() {
var x1 = document.getElementById("dd").value;
$.ajax({
	 url:"showResults.php",
	 method: "POST",
	 data:{id1 : x1},
	 success:function(data){
			 //Replace the table content with the data received through ajax
			 $("#ans").html(data);
		 //Initialize DataTables with the required options
		 var table = new DataTable('#myTable', {
	 dom: 'Bfrtip',
			 buttons: [
		 {
	 extend: 'excel',
	 text: 'Excel',
	 exportOptions: {
		 rows: function(idx, data, node) {
		 let found = false;
		 if ($("#exportSelected").is(":checked")) {
			 let selectedRowIndexes = table.rows('.selected').indexes();
			 for (let index = 0; index < selectedRowIndexes.length; index++) {
			 if (idx == selectedRowIndexes[index]) {
				 found = true;
				 break;
			 }
			 }
			 return found;
		 } else {
			 return true;
		 }
		 }
	 }
	 }
	 ],
	 columnDefs: [
	 {
		 orderable: false,
		 className: 'select-checkbox',
		 targets: 0
	 }
],
select: {
	 style: 'multi',
	 selector: 'td:first-child'
},
order: [[1, 'asc']]
});
// Make the table visible and expose the DataTables API.
table.tables({visible: true, api: true});
// Destroy the DataTables object.
table.destroy();
	 }
});
}




#2
radu103

radu103

    Guru Member

  • Grup: Senior Members
  • Posts: 12,206
  • Înscris: 15.11.2003
Eu am folosit fara probleme dupa urmatoarea logica :
- se iau datele in js si se creaza DataTable
- cand se schimba datele se distruge si apoi se creaza din nou acel DataTable

Din ce vad la tine n-ai facut destroy la inceput ?

#3
geotux

geotux

    Junior Member

  • Grup: Junior Members
  • Posts: 49
  • Înscris: 12.07.2019
OK, am rezolvat:

function selectSpecie() {
	var x1 = document.getElementById("dd").value;

	$.ajax({
		url: "showResults.php",
		method: "POST",
		data: { id1: x1 },
		success: function (data) {
			DataTable
				.tables( { visible: true, api: true } )
				.destroy();

			//Replace the table content with the data received through ajax
			$("#ans").html(data);

			//Initialize DataTables with the required options

			var table = new DataTable("#myTable", {
				dom: "Bfrtip",
				buttons: [
					{
						extend: "excel",
						text: "Excel",
						exportOptions: {
							rows: function (idx, data, node) {
								let found = false;
								if ($("#exportSelected").is(":checked")) {
									let selectedRowIndexes = table.rows(".selected").indexes();
									for (
										let index = 0;
										index < selectedRowIndexes.length;
										index++
									) {
										if (idx == selectedRowIndexes[index]) {
											found = true;
											break;
										}
									}
									return found;
								} else {
									return true;
								}
							},
						},
					},
				],
				columnDefs: [
					{
						orderable: false,
						className: "select-checkbox",
						targets: 0,
					},
				],
				select: {
					style: "multi",
					selector: "td:first-child",
				},
				order: [[1, "asc"]],
			});
		},
	});
}



Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate