I am using Tabulator to create a table. I import information from JSON file using ajaxURL: "test.json". Data all loads fine. I have created a form to enter data into. When submitted, it goes to a PHP file that processes the data (decodes test.json, adds form data, encodes to json). Everything works fine until I try to implement a way of deleting. I have tried a few ways and none of them work. One way would create nested arrays within my json array and Tabulator will not read that. I want to be able to click the buttonCross in my Delete column and delete the row from the table and from the JSON file.

Is there anyway do delete JSON file elements without nesting arrays?


<form action="process.php" method="POST">
        <input type="text" name="name">
        <input type="text" name="descript">
        <input type="text" name="lat">                
        <input type="text" name="lon">
        Start Date/Time:
        <input type="date" name="startDate">
        <input type="time" name="startTime">
        End Date/Time:
        <input type="date" name="endDate">
        <input type="time" name="endTime">
        <input type="hidden" name="deleteStatus" value="">

        <input type="submit" value="Submit">
        <input type="reset" value="Reset">

//later in the file

columns:[                 //define the table columns
                {title:"Delete", field:"deleteStatus", formatter:"buttonCross", width:50, align:"center", headerSort:false, cellClick:function(e, cell){
                    if(confirm('Are you sure you want to delete this entry?')) {
                        var row = cell.getRow();

                            url: 'process.php',
                            method: 'post',
                            data: {row},



$myFile = "test.json";
$arr_data = array(); // create empty array
$time = date("YmdHis");

    //Get form data
    $formdata = array(
        'id'=> $time,
        'deleteStatus'=> $_POST['deleteStatus'],
        'name'=> $_POST['name'],
        'descript'=> $_POST['descript'],
        'lat'=> $_POST['lat'],
        'lon'=> $_POST['lon'],
        'startDate'=> $_POST['startDate'],
        'startTime'=> $_POST['startTime'],
        'endDate'=> $_POST['endDate'],
        'endTime'=> $_POST['endTime'],

    //Get data from existing json file
    $jsondata = file_get_contents($myFile);

    // converts json data into array
    $arr_data = json_decode($jsondata, true);

    // Push user data to array

    foreach($arr_data as $elementKey => $element) {
        foreach($element as $valueKey => $value) {
            if($valueKey == 'deleteStatus' && $value == 'delete'){
                //delete this particular object from the $array

    //Convert updated array to JSON
    $jsondata = json_encode($arr_data, JSON_PRETTY_PRINT);

    //write json data into data.json file
    if(file_put_contents($myFile, $jsondata)) {
        header("Refresh:0; url = tabulator.html");
        echo "error";

catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";

1 Answers

Mr Singh On Best Solutions

Check documentation you need to call an API ( like node.js) to which deletes form the json file

    //Call your api to delete from JSON file 
    //handle error deleting row

    //run code after row has been deleted
    //handle error deleting row