插入后JsGrid不显示数据

时间:2019-11-24 04:05:46

标签: javascript php jquery jsgrid

当我插入新行时,数据将插入数据库中,但是在jsgrid中数据为空 我需要刷新页面以显示新行

enter image description here

然后我刷新页面...

enter image description here

这是我的代码JavaScript:

$.ajax({
        url: BASE_URL + 'mesas/get_mesas_ajax',
        async: false,
        success: function(result){
            mesasDados = result;
        }
    });

    let mesa = JSON.parse(mesasDados);




    $("#jsGrid-basic").jsGrid({
        width: "100%",
        height: "400px",

        inserting: true,
        editing: true,
        sorting: true,
        paging: true,
        deleteConfirm: "Deseja mesmo excluir essa mesa ?",

        data: mesa,

    controller: {

      insertItem: function(item){
       return $.ajax({
        type: "POST",
        url: "mesas/ajax_save_mesa",
        data:item
       });
      },
      updateItem: function(item){
       return $.ajax({
        type: "POST",
        url: "mesas/ajax_update_mesa",
        data: item
       });
      },
      deleteItem: function(item){
       return $.ajax({
        type: "POST",
        url: "mesas/ajax_delete_mesa",
        data: item
       });
      },
     },

        fields: [
            {name: "idmesa", type: "text", css: "hide"},
            { name: "mesa", title: "Numero mesa", type: "number", width: 150, validate: "required", css:"text-center" },
            { name: "senhamesa", title: "Senha", type: "text", width: 150, css:"text-center" },
            { name: "descricao", title: "Descricao", type: "text", width: 150, css:"text-center" },
            { type: "control" }
        ]
    });

我的代码PHP用于插入:

public function ajax_save_mesa(){
    if(!$this->input->is_ajax_request()){
        exit('Não é possivel acesso direto!');
    }

    $dados = $this->input->post();

    unset($dados["idmesa"]);

    $this->load->model("mesas_model");
    $mesas = $this->mesas_model->insert($dados);


}

0 个答案:

没有答案