Comments (4)
This is the one that works (loaddata.php)
<?php session_start();
/*
* examples/mysql/loaddata.php
*
* This file is part of EditableGrid.
* http://editablegrid.net
*
* Copyright (c) 2011 Webismymind SPRL
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://editablegrid.net/license
*/
/**
* This script loads data from the database and returns it to the js
*
*/
require_once('config.php');
require_once('EditableGrid.php');
/**
* fetch_pairs is a simple method that transforms a mysqli_result object in an array.
* It will be used to generate possible values for some columns.
*/
function fetch_pairs($mysqli,$query){
if (!($res = $mysqli->query($query)))return FALSE;
$rows = array();
while ($row = $res->fetch_assoc()) {
$first = true;
$key = $value = null;
foreach ($row as $val) {
if ($first) { $key = $val; $first = false; }
else { $value = $val; break; }
}
$rows[$key] = $value;
}
return $rows;
}
// Database connection
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
$mysqli->real_connect($config['db_host'],$config['db_user'],$config['db_password'],$config['db_name']);
// create a new EditableGrid object
$grid = new EditableGrid();
/*
* Add columns. The first argument of addColumn is the name of the field in the databse.
* The second argument is the label that will be displayed in the header
*/
$grid->addColumn('id_muestra', 'Clave', 'string', fetch_pairs($mysqli,'SELECT id,clave FROM muestras WHERE muestras.id_salida='.$_SESSION['idsalida'] ),true);
$grid->addColumn('especie', 'Especie', 'string');
$grid->addColumn('colector', 'Colector', 'string');
$grid->addColumn('perforaciones', 'Perforaciones', 'boolean');
$grid->addColumn('vermes', 'Vermes', 'boolean');
$grid->addColumn('ectoparasitos', 'Ectoparásitos', 'boolean');
$grid->addColumn('hongos_bacterias', 'Hongos o Bacterias', 'boolean');
$grid->addColumn('deformidades', 'Deformidades', 'boolean');
$grid->addColumn('lesiones', 'Lesiones', 'boolean');
$grid->addColumn('olores', 'Olores', 'boolean');
$grid->addColumn('observaciones', 'Observaciones', 'string');
$grid->addColumn('verificado', 'Verificado', 'boolean');
$grid->addColumn('borrar', 'Borrar', 'boolean');
$result = $mysqli->query('SELECT * FROM biologicos WHERE biologicos.id_muestra IN (SELECT id FROM muestras WHERE muestras.id_salida='.$_SESSION['idsalida'].' ) or biologicos.id_muestra<0 '); // LIMIT 100'
$mysqli->close();
// send data to the browser
$grid->renderXML($result);
This is the one that not
<?php session_start();
/*
* examples/mysql/loaddata.php
*
* This file is part of EditableGrid.
* http://editablegrid.net
*
* Copyright (c) 2011 Webismymind SPRL
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://editablegrid.net/license
*/
/**
* This script loads data from the database and returns it to the js
*
*/
require_once('config.php');
require_once('EditableGrid.php');
// create a new EditableGrid object
$grid = new EditableGrid();
/**
* fetch_pairs is a simple method that transforms a mysqli_result object in an array.
* It will be used to generate possible values for some columns.
*/
function fetch_pairs($mysqli,$query){
if (!($res = $mysqli->query($query)))return FALSE;
$rows = array();
while ($row = $res->fetch_assoc()) {
$first = true;
$key = $value = null;
foreach ($row as $val) {
if ($first) { $key = $val; $first = false; }
else { $value = $val; break; }
}
$rows[$key] = $value;
}
return $rows;
}
// Database connection
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
$mysqli->real_connect($config['db_host'],$config['db_user'],$config['db_password'],$config['db_name']);
#$grid->addColumn('id_muestra', 'Clave', 'string', fetch_pairs($mysqli,'SELECT id,clave FROM muestras WHERE muestras.id_salida='.$_SESSION['idsalida'] ),true);
$grid->addColumn('identificador', 'ID', 'integer', NULL, true);
$grid->addColumn('id_muestra', 'muestra', 'integer', NULL, true);
$grid->addColumn('id_submuestra', 'submuestra', 'integer', NULL, true);
$grid->addColumn('id_laminilla', 'laminilla', 'integer', NULL, true);
$grid->addColumn('nombre', 'Nombre', 'string', NULL, true);
$grid->addColumn('localizacion', 'localizacion', 'string', NULL, true);
$grid->addColumn('observaciones', 'Observaciones', 'string', NULL, true);
$grid->addColumn('verificado', 'Verificado', 'boolean', NULL, true);
$grid->addColumn('borrar', 'Borrar', 'boolean', NULL, true);
$result = $mysqli->query('SELECT * FROM fotografias where 1'); // LIMIT 100'
$mysqli->close();
// send data to the browser
$grid->renderXML($result);
from editablegrid-mysql-example.
This are the js files, the one that works
/**
* highlightRow and highlight are used to show a visual feedback. If the row has been successfully modified, it will be highlighted in green. Otherwise, in red
*/
function highlightRow(rowId, bgColor, after)
{
var rowSelector = $("#" + rowId);
rowSelector.css("background-color", bgColor);
rowSelector.fadeTo("normal", 0.5, function() {
rowSelector.fadeTo("fast", 1, function() {
rowSelector.css("background-color", '');
});
});
}
function highlight(div_id, style) {
highlightRow(div_id, style == "error" ? "#e5afaf" : style == "warning" ? "#ffcc00" : "#8dc70a");
}
/**
updateCellValue calls the PHP script that will update the database.
*/
function updateCellValue(editableGrid, rowIndex, columnIndex, oldValue, newValue, row, onResponse)
{
$.ajax({
url: 'update.php',
type: 'POST',
dataType: "html",
data: {
tablename : editableGrid.name,
id: editableGrid.getRowId(rowIndex),
newvalue: editableGrid.getColumnType(columnIndex) == "boolean" ? (newValue ? 1 : 0) : newValue,
colname: editableGrid.getColumnName(columnIndex),
coltype: editableGrid.getColumnType(columnIndex)
},
success: function (response)
{
// reset old value if failed then highlight row
var success = onResponse ? onResponse(response) : (response == "ok" || !isNaN(parseInt(response))); // by default, a sucessfull reponse can be "ok" or a database id
if (!success) editableGrid.setValueAt(rowIndex, columnIndex, oldValue);
highlight(row.id, success ? "ok" : "error");
},
error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },
async: true
});
}
function DatabaseGrid()
{
this.editableGrid = new EditableGrid("biologicos", {
enableSort: true,
tableLoaded: function() { datagrid2.initializeGrid(this); },
modelChanged: function(rowIndex, columnIndex, oldValue, newValue, row) {
updateCellValue(this, rowIndex, columnIndex, oldValue, newValue, row);
}
});
this.fetchGrid();
}
DatabaseGrid.prototype.fetchGrid = function() {
// call a PHP script to get the data
this.editableGrid.loadXML("loaddata_biologicos.php");
};
DatabaseGrid.prototype.initializeGrid = function(grid) {
grid.renderGrid("tablecontent", "testgrid");
};
This is the one that doesnt work
/**
* highlightRow and highlight are used to show a visual feedback. If the row has been successfully modified, it will be highlighted in green. Otherwise, in red
*/
function highlightRow(rowId, bgColor, after)
{
var rowSelector = $("#" + rowId);
rowSelector.css("background-color", bgColor);
rowSelector.fadeTo("normal", 0.5, function() {
rowSelector.fadeTo("fast", 1, function() {
rowSelector.css("background-color", '');
});
});
}
function highlight(div_id, style) {
highlightRow(div_id, style == "error" ? "#e5afaf" : style == "warning" ? "#ffcc00" : "#8dc70a");
}
/**
updateCellValue calls the PHP script that will update the database.
*/
function updateCellValue(editableGrid, rowIndex, columnIndex, oldValue, newValue, row, onResponse)
{
$.ajax({
url: 'update.php',
type: 'POST',
dataType: "html",
data: {
tablename : editableGrid.name,
id: editableGrid.getRowId(rowIndex),
newvalue: editableGrid.getColumnType(columnIndex) == "boolean" ? (newValue ? 1 : 0) : newValue,
colname: editableGrid.getColumnName(columnIndex),
coltype: editableGrid.getColumnType(columnIndex)
},
success: function (response)
{
// reset old value if failed then highlight row
var success = onResponse ? onResponse(response) : (response == "ok" || !isNaN(parseInt(response))); // by default, a sucessfull reponse can be "ok" or a database id
if (!success) editableGrid.setValueAt(rowIndex, columnIndex, oldValue);
highlight(row.id, success ? "ok" : "error");
},
error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },
async: true
});
}
function DatabaseGrid()
{
this.editableGrid = new EditableGrid("fotografias", {
enableSort: true,
tableLoaded: function() { datagrid2.initializeGrid(this); },
modelChanged: function(rowIndex, columnIndex, oldValue, newValue, row) {
updateCellValue(this, rowIndex, columnIndex, oldValue, newValue, row); }
});
this.fetchGrid();
}
DatabaseGrid.prototype.fetchGrid = function() {
// call a PHP script to get the data
this.editableGrid.loadXML("loaddata_fotografias.php");
};
DatabaseGrid.prototype.initializeGrid = function(grid) {
grid.renderGrid("tablecontent", "testgrid");
};
from editablegrid-mysql-example.
I tried the demo exactly as it is and still dont work
I change only the config.php file in order to add the db info and the table doesnt appear
from editablegrid-mysql-example.
Please check this url /loaddata.php
Please share, what data it has??
from editablegrid-mysql-example.
Related Issues (20)
- loaddata.php patch
- Update fields
- How do I get set up the grid so all columns can be filtered? HOT 2
- no hidden column HOT 1
- date from datepicker - no update
- how to upload file ?
- multiple editablegrid HOT 2
- url in a cell HOT 2
- multiple primary key for one table
- Filter not working on all columns HOT 1
- ErrorCode "Call to undefined function mysqli_init()"
- response == "ok" fails because of line break in "ok" string
- sorting date column only sorts by day and ignores month and year HOT 1
- Time picker?
- javascript error on demo with current mysql table HOT 1
- New columns added make grid go blank
- How to make every column header into individual filter
- Link to an URL / Website
- hidde column doesn work
- Question about addRow process
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from editablegrid-mysql-example.