jQuery UI Widgets › Forums › Grid › Pivot Grid with PHP-MySQL data source
Tagged: #pivotgrid, data source, javascript pivotgrid, jquery pivotgrid, jqwidgets pivotgrid, mysql, php, pivot
This topic contains 4 replies, has 3 voices, and was last updated by Hristo 6 years, 8 months ago.
-
Author
-
Good day,
Please I want to know if it is possible to use a data source from PHP-MySQL with the new pivot grid? I have done everything I know but its not loading the data. I don’t know if there is something am doing wrong. Below is a sample of what am doing but please if there is an example of what I should do, it will be GREATLY appreciated.<script type=”text/javascript”>
$(document).ready(function () {// create a data source and data adapter
var source =
{
datatype: “json”,
url: ‘DB/pivotPHPdb.php’,
datafields:
[
{ name: ‘month’, type: ‘string’ },
{ name: ‘projects’, type: ‘string’ },
{ name: ‘locations’, type: ‘string’ },
{ name: ‘gender’, type: ‘string’ },
{ name: ‘age’, type: ‘string’ },
{ name: ‘volunteer_workers’, type: ‘number’ },
{ name: ‘patient_tested’, type: ‘number’ }
]
};var dataAdapter = new $.jqx.dataAdapter(source);
dataAdapter.dataBind();// create a pivot adapter from the dataAdapter
var pivotAdapter = new $.jqx.pivot(
dataAdapter,
{
pivotValuesOnRows: false,totals: {rows: {subtotals: true, grandtotals: true}, columns: {subtotals: false, grandtotals: true}},
rows: [
{ dataField: ‘projects’ },
{ dataField: ‘locations’ }
],columns: [
{ dataField: ‘gender’ }
],values: [
{ dataField: ‘volunteer_workers’, ‘function’: ‘sum’, text: ‘sum’ },
{ dataField: ‘patient_tested’, ‘function’: ‘sum’, text: ‘sum’ }
]
});// create a pivot grid
$(‘#divPivotGrid’).jqxPivotGrid(
{
source: pivotAdapter,
treeStyleRows: true,
autoResize: false,
multipleSelectionEnabled: true
});
});
</script>Thanks.
Hello teggs,
You could try to check is there any data in the DataAdapter – with
console.log(DataAdapter);
after “dataAdapter.dataBind();”
Also, it will be better if you implementloadError(jqXHR, status, error):
callback to the DataAdapter to understand if there is some error.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comDear Sir,
I want to use a data source from PHP-MySQL with the new pivot grid,but its not loading the data.
My dtas is getting displayed in the alert box. Please find below my coding. Please advice me.$(document).ready(function() {
ObtenerDatos();
});function ObtenerDatos() {
var url = “data.php”;
$.ajax({
type: “POST”,
url: url,
success: function(data) {
BindPivot(data);
}
});
}function BindPivot(data)
{
alert(data); //my data is getting displayed in the alert box
var source =
{
datatype: “json”,
datafields: [
{ name: ‘productID’, type: ‘string’ },
{ name: ‘price’, type: ‘float’ }
],};
var dataAdapter = new $.jqx.dataAdapter(source);
dataAdapter.dataBind();// create a pivot data source from the dataAdapter
var pivotDataSource = new $.jqx.pivot(
dataAdapter,
{pivotValuesOnRows: false,
rows: [{ dataField: ‘productID’, width: 190 }],
columns: [],
values: [
{ dataField: ‘price’, width: 200, ‘function’: ‘min’, text: ‘cells left alignment’, formatSettings: { align: ‘left’, prefix: ”, decimalPlaces: 2, } },
{ dataField: ‘price’, width: 200, ‘function’: ‘max’, text: ‘cells center alignment’, formatSettings: { align: ‘center’, prefix: ”, decimalPlaces: 2 } },
{ dataField: ‘price’, width: 200, ‘function’: ‘average’, text: ‘cells right alignment’, formatSettings: { align: ‘right’, prefix: ”, decimalPlaces: 2 } }
]
});// create a pivot grid
$(‘#divPivotGrid’).jqxPivotGrid(
{
source: pivotDataSource,
treeStyleRows: false,
autoResize: false,
multipleSelectionEnabled: true
});}
Dear sir,
When i include ” localdata: data”, my datas are getting loaded. Please confirm, if i am going in the right path. Thanks
var source =
{
localdata: data,//////////////// This line
datatype: “json”,
datafields: [
{ name: ‘productID’, type: ‘string’ },
{ name: ‘price’, type: ‘float’ }
],//url: ‘data_pivotgrid_cell_values_alignment.php’,
//cache: false,
};Hello yaline,
You could use
localdata
orurl
properties of the DataAdapter’s source depends on case.
Please, take a look at the API Documentation of the DataAdapter for more details:
https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdataadapter/jquery-data-adapter.htm?search=data
I would like to suggest you implement theloadError(jqXHR, status, error)
callback to check if there has some error.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.