本文介绍了如何使用jQuery SlickGrid用PHP / MySQL的(负载服务器的数据并保存更改)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在所有在 SlickGrid code中的例子中,数据阵随机在客户端生成的

Please, in all the examples found in the SlickGrid code, the data array was randomly generated on the client side.

入门:我需要知道如何使用PHP从MySQL数据库获取此信息,并使用jQuery / AJAX的SlickGrid归还

Getting: I need to know how to use PHP to fetch this information from a MySQL Database and return it using jQuery / AJAX to the SlickGrid.

保存:我已经发现了计算器一个链接,使用一个隐藏的输入(的 -in-slickgrid>保存修改),但它不是真正清楚如何我应该来处理得到的PHP脚本此数据。

Saving: I already found a link on StackOverflow for saving data from the grid using a hidden input (Saving changes in SlickGrid) but it's not really clear how I ought to handle this data on getting to the PHP script.

一些详细的帮助和/或指针将AP preciated,我宁愿一个小白,我没有找到这真棒插件足够的文档。

Some detailed help and/or pointers will be appreciated, I'm rather a noob and I did not find adequate documentation on this awesome plugin.

推荐答案

SlickGrid需要数据数组,以填充表。您可以创建此作为一个字符串在PHP和使用,在你当你创建你的SlickGrid的JavaScript。

SlickGrid needs an array of data in order to populate the table. You can create this as a string in PHP and use that in your JavaScript when you create your SlickGrid.

请注意;这是快速的,肮脏的和未经考验的!

Please note; this is quick, dirty and untested!

PHP

$data = '';
$i = 0;

$query = "
    SELECT
        `title`, `duration`, `percentComplete`, `start`, `finish`, `effortDriven`
    FROM
        `myTable`
";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    $data .= '
        data['.$i.'] = {
            title: "'.$row['title'].'",
            duration: "'.$row['duration'].'",
            percentComplete: "'.$row['percentComplete'].'",
            start: "'.$row['start'].'",
            finish: "'.$row['finish'].'",
            effortDriven: "'.$row['percentComplete'].'"
        };
    ';

    $i++;
}

的JavaScript

<script type="text/javascript">
    var grid;

    var columns = [
        {id:"title", name:"Title", field:"title"},
        {id:"duration", name:"Duration", field:"duration"},
        {id:"%", name:"% Complete", field:"percentComplete"},
        {id:"start", name:"Start", field:"start"},
        {id:"finish", name:"Finish", field:"finish"},
        {id:"effort-driven", name:"Effort Driven", field:"effortDriven"}
    ];

    var options = {
        enableCellNavigation: false,
        enableColumnReorder: false
    };

    $(function() {
        var data = [];
        <?php echo $data; ?> //This is where we echo the PHP variable $data which contains our JavaScript array as a string.

        grid = new Slick.Grid($("#myGrid"), data, columns, options);
    })
</script>

这篇关于如何使用jQuery SlickGrid用PHP / MySQL的(负载服务器的数据并保存更改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!