0
votes

I am using SlickGrid/DataView for CRUD purposes. It is working fine. However, we have some of the tables which do not have primary key.

Q1: How can I use dataview for such tables? If not then am I left with using Slickgrid without dataview only OR I have another choice? Any example would be appreciated.

Q2: Does Dataview support composite primary keys? If yes, can anybody give me an example of using it?

thanks

1

1 Answers

0
votes

SlickGrid requires at least the ID field, you can take whichever that could be named differently in your table and then alias it to "ID" but it has to be a UNIQUE id field because SlickGrid is using it for row naming and so on.

If you do not have a UNIQUE field and you really want to use composite primary keys, then I suggest you create a fake ID field which you simply increment by 1 each loop. A simple way is to do this while fetching the data, something similar to the following:

$sqlTable = "SELECT * FROM myTable";
$result = mysql_query($sqlTable,$connMySQL);

$i = 1;
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    $tabData[] = array( 
        "id" => $i++, 
        "column1" => $row['column1'],
        "column2" => $row['column2'] 
    );
}

Now if you do use a fake ID like I just said, this will give you some problems doing the CRUD (update, delete) since your ID is not real and point to nowhere... but there is a way to fix that too.

By the way, you should split your question into 2 separate question since they are different subjects. I suggest you ask your CRUD subject in another question and that you provide some code so we can develop from there.