public function getGridForTable($table, $columns, $showdelete) { global $CFG; // Database connection $conn = mysqli_connect($CFG->db, $CFG->dbuser, $CFG->dbuserpass, $CFG->schema) or die("<data><error>cannot select {$CFG->schema}</error><detail>" . mysqli_error($conn) . "</detail></data>"); // build a mapping of the table for comparison $query = "SHOW COLUMNS FROM `{$table}`"; $result = mysqli_query($conn, $query) or die("<data><error>cannot show columns from records, query was {$query}</error><detail>" . mysqli_error($conn) . "</detail></data>"); $rawfieldsmap = array(); // build a map of existing fields while ($row = mysqli_fetch_array($result)) { $rawfieldsmap[] = $row['Field'] . ',' . $row['Type']; } $result = mysqli_query($conn, "SELECT * FROM {$table} WHERE `editable` = 'true' AND COALESCE (`deleted`, '') <> 'true' ORDER BY ID DESC"); // create a new EditableGrid object $grid = new EditableGrid(); // get the columns $columnsArr = explode(',', $columns); // print_r($columnsArr); /* * 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', 'ID', 'integer', NULL, false); foreach ($columnsArr as $column) { foreach ($rawfieldsmap as $fieldsmapelement) { $fieldsmapelementArr = explode(',', $fieldsmapelement); if ($column == $fieldsmapelementArr[0]) { if (stripos($fieldsmapelementArr[0], "int") !== false) { $grid->addColumn($column, $column, 'integer'); } else { $grid->addColumn($column, $column, 'string'); } } } } if ($showdelete) { $grid->addColumn("Delete", 'Delete', 'string', NULL, false); } // send data to the browser return $grid->renderXML($result); }
* examples/full/datasource/demo.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 PHP script demonstrates how to generate XML grid data "on-the-fly" // To achieve this, here we use our simple "PHP wrapper class" EditableGrid.php, but this is not mandatory. // The only thing is that the generated XML must have the expected structure . // Here we get the data from a CSV file; in real life, these data would probably come from a database. require_once "../../../php/EditableGrid.php"; // create grid and declare its columns $grid = new EditableGrid(); // add two "string" columns // if you wish you can specify the desired length of the text edition field like this: string(24) $grid->addColumn("name", "NAME", "string"); $grid->addColumn("firstname", "FIRSTNAME", "string"); // add an "integer" and a "double" column // you can specifiy the unit: double(m), the precision: double(2), or both: double(m,2) // these will be used in the default renderer NumberCellRenderer $grid->addColumn("age", "AGE", "integer"); $grid->addColumn("height", "HEIGHT", "double(m,2)", null, true, null, false); // add column with predefined values, organized in "option groups" (dropdown list) $grid->addColumn("country", "COUNTRY", "string", array("Europe" => array("be" => "Belgium", "fr" => "France", "uk" => "Great-Britain", "nl" => "Nederland"), "America" => array("br" => "Brazil", "ca" => "Canada", "us" => "USA"), "Africa" => array("ng" => "Nigeria", "za" => "South-Africa", "zw" => "Zimbabwe"))); // add some other columns: email, url, boolean, date $grid->addColumn("email", "EMAIL", "email"); // $grid->addColumn("website", "WEBSITE", "url"); $grid->addColumn("freelance", "FREELANCE", "boolean");
$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', 'ID', 'integer', NULL, false); $grid->addColumn('name', 'Name', 'string'); $grid->addColumn('firstname', 'Firstname', 'string'); $grid->addColumn('age', 'Age', 'integer'); $grid->addColumn('height', 'Height', 'float'); /* The column id_country and id_continent will show a list of all available countries and continents. So, we select all rows from the tables */ $grid->addColumn('id_continent', 'Continent', 'string', fetch_pairs($mysqli, 'SELECT id, name FROM continent'), true); $grid->addColumn('id_country', 'Country', 'string', fetch_pairs($mysqli, 'SELECT id, name FROM country'), true); $grid->addColumn('email', 'Email', 'email'); $grid->addColumn('freelance', 'Freelance', 'boolean'); $grid->addColumn('lastvisit', 'Lastvisit', 'date');
$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('ALUNOATIV_ALUNO_CDG', 'Aluno', 'integer', NULL, false); $grid->addColumn('ATIVIDADE_NOME', 'Atividade', 'string'); $grid->addColumn('ALUNOATIV_ACERTOS', 'Acertos', 'integer'); $grid->addColumn('ALUNOATIV_ERROS', 'Erros', 'integer'); //$grid->addColumn('firstname', 'Firstname', 'string'); //$grid->addColumn('age', 'Age', 'integer'); //$grid->addColumn('height', 'Height', 'float'); /* The column id_country and id_continent will show a list of all available countries and continents. So, we select all rows from the tables */ $grid->addColumn('ALUNO_NOME', 'ALUNO', 'string', fetch_pairs($mysqli, 'SELECT ALUNO_CDG, ALUNO_NOME FROM ALUNO'), true); $grid->addColumn('TURMA', 'Turma', 'STRING', NULL, false); //$grid->addColumn('id_continent', 'Continent', 'string' , fetch_pairs($mysqli,'SELECT id, name FROM continent'),true);
<?php require "../Common/ConfigSql.php"; require "../Common/Common.php"; require_once '../Common/EditableGrid.php'; global $mysqliDB; global $ErrorSQL; OpenDB(); // 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', 'ID', 'string', NULL, false); $grid->addColumn('Dorsal', 'Dorsal', 'string', NULL, false); $grid->addColumn('Piloto', 'Piloto', 'string', NULL, false); $maxvuelos = 0; if (isset($_REQUEST["Concurso"])) { $concurso = $_REQUEST["Concurso"]; $sql = "SELECT MAX(`RoundNo`) AS MaxVuelos FROM scores where CompNo=" . $concurso . ";"; $resultado = $mysqliDB->query($sql); if (!$resultado) { echo "Error in " . $sql . " (" . $mysqliDB->errorCode() . ")"; die; } $row = $resultado->fetch(PDO::FETCH_ASSOC); $maxvuelos = $row['MaxVuelos']; for ($i = 1; $i <= $maxvuelos; $i++) { $grid->addColumn("Time1Mins" . $i, "Tie {$i}", 'integer'); $grid->addColumn("Landing" . $i, "Ate {$i}", 'integer');
$key = $value = null; foreach ($row as $val) { if ($first) { $key = $val; $first = false; } else { $value = $val; break; } } $rows[$key] = $value; } return $rows; } // 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', 'Cdg', 'integer', NULL, false); $grid->addColumn('TURMA_NOME', 'Série', 'string'); $grid->addColumn('TURMA_ANO', 'Ano', 'string'); //$grid->addColumn('firstname', 'Firstname', 'string'); //$grid->addColumn('age', 'Age', 'integer'); //$grid->addColumn('height', 'Height', 'float'); /* The column id_country and id_continent will show a list of all available countries and continents. So, we select all rows from the tables */ $grid->addColumn('TURMA_PROF', 'Prof.', 'string', fetch_pairs($System, 'SELECT USUARIO_CDG,USUARIO_NOME ' . ' FROM USUARIO ' . ' LEFT JOIN USUARIO_ESCOLA ON USUARIOESCOLA_USUARIO = USUARIO_CDG ' . ' WHERE USUARIOESCOLA_ESCOLA = ' . $_SESSION['ESCOLA']), true); //$grid->addColumn('TURMA', 'Turma', 'STRING',NULL,false); //$grid->addColumn('id_continent', 'Continent', 'string' , fetch_pairs($mysqli,'SELECT id, name FROM continent'),true); //$grid->addColumn('id_country', 'Country', 'string', fetch_pairs($mysqli,'SELECT id, name FROM country'),true );
} } $rows[$key] = $value; } return $rows; } //Load target page info by SESSION. $targetDatabaseTableName = $_SESSION['targetTableName']; $targetPageSwitch = $_SESSION['targetPageSwitch']; $targetSemesterWeek = $_SESSION['targetSemesterWeek']; // 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 * The third argument is the display type of grid */ foreach ($GRID_KEY_NAMES_ARRAY[$targetPageSwitch] as $key => $value) { if ($key == 'id') { $grid->addColumn('id', 'ID', 'integer', NULL, false); continue; } $grid->addColumn($key, $value, 'string'); } //Create the SQL Syntax. if ($targetPageSwitch != $COURSE_PERIOD_PAGE_SWITCH && $targetPageSwitch != $WEEKS_SCHEDULE_PAGE_SWITCH) { $sqlSelectSyntax = "SELECT * FROM {$targetDatabaseTableName} WHERE SEMESTER_WEEK = {$targetSemesterWeek}";
$key = $value = null; foreach ($row as $val) { if ($first) { $key = $val; $first = false; } else { $value = $val; break; } } $rows[$key] = $value; } return $rows; } // 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('ALUNO_CDG', 'Cdg', 'integer', NULL, false); $grid->addColumn('ALUNO_NOME', 'Nome', 'string'); $grid->addColumn('ALUNO_PONTOS', 'Pontos', 'integer'); $grid->addColumn('ALUNO_DTNASC', 'Nascimento', 'date', NULL, true, 'nasc'); //$grid->addColumn('firstname', 'Firstname', 'string'); //$grid->addColumn('age', 'Age', 'integer'); //$grid->addColumn('height', 'Height', 'float'); /* The column id_country and id_continent will show a list of all available countries and continents. So, we select all rows from the tables */ //$grid->addColumn('ALUNO_NOME', 'ALUNO', 'string' , fetch_pairs($mysqli,'SELECT ALUNO_CDG, ALUNO_NOME FROM ALUNO'),true); //$grid->addColumn('TURMA', 'Turma', 'STRING',NULL,false); //$grid->addColumn('id_continent', 'Continent', 'string' , fetch_pairs($mysqli,'SELECT id, name FROM continent'),true);
$key = $value = null; foreach ($row as $val) { if ($first) { $key = $val; $first = false; } else { $value = $val; break; } } $rows[$key] = $value; } return $rows; } // 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('ALUNO_CDG', 'Cdg', 'integer', NULL, false); $grid->addColumn('ALUNO_NOME', 'Nome', 'string'); $grid->addColumn('ALUNO_LOGIN', 'Login', 'string'); $grid->addColumn('ALUNO_PONTOS', 'Pontos', 'integer', null, false); $grid->addColumn('ALUNO_NIVEL', 'Nível', 'integer', null, false); $grid->addColumn('ALUNO_SEXO', 'Sexo', 'string'); $grid->addColumn('ALUNO_RGM', 'RGM', 'integer'); $grid->addColumn('ALUNO_RA', 'RA', 'string'); $grid->addColumn('ALUNO_STATUS', 'Status', 'string'); $grid->addColumn('TURMA_NOME', 'Turma', 'string', null, false); $grid->addColumn('ALUNO_DTNASC', 'Nascimento', 'date', NULL, true, 'ALUNO_NASCIMENTO');