Updating cells in Datatable

Updating cells in Datatable

mihalispmihalisp Posts: 127Questions: 22Answers: 0

Hi everyone,
I am trying to do the following.

I have a Datatable with data (JSON) returned from a complex php SQL query (Multiple Left Joins,Coalesce etc.).I want to update the value of specific cells in a column by double clicking on it.

My worries are:
1) How to use the onclick event?

2) Do i have to use editor so that i can update cells?(I think i do)

3) If i have to use Editor,I can't use my same complex query neither i can transform it to match the format of serverside SQL that editor make use of.

4) Is it possible to tell editor use SQl script that uses only 1 table and updates only the field i want (column 5) when i double click the specific cell.In that case,is it necessary to use checkboxes in the 1st column of the Datatable?

5) Finally,after the successful update of the cell will the change (the new value) be visible automatically or should i draw the table again.And if i draw it again,will the Datatable keep its state,i mean will i be able to see the current page i was earlier when i updated the cell?

Thank you in advance.

Answers

  • kthorngrenkthorngren Posts: 20,315Questions: 26Answers: 4,772

    1) How to use the onclick event?

    Do you want to pull up a form to edit the cell or just inline like a text input?

    2) Do i have to use editor so that i can update cells?(I think i do)

    I use Editor for most all of my tables that have editable data I want to store in a DB. However there are some instances where it might be easier just to have a simple input then post the updated data to the server using a custom jQuery Ajax call.

    3) If i have to use Editor,I can't use my same complex query neither i can transform it to match the format of serverside SQL that editor make use of.

    I've never used the server side Editor code so not sure what options you have. The reason mostly is I use Python for my server. I create my own server code and let Editor post to it. This way I can execute whatever SQL queries I want. You could do the same.

    5) Finally,after the successful update of the cell will the change (the new value) be visible automatically or should i draw the table again.And if i draw it again,will the Datatable keep its state,i mean will i be able to see the current page i was earlier when i updated the cell?

    The draw() API has a paging parameter that can control. You can pass false or "page" and stay on the same page. However if the column you are updating is being sorted then that row may move somewhere else.

    @allan or @colin can provide more specifics about how or if the server side Editor code can handle your complex SQL queries.

    Kevin

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    Thanks for the quick reply.

    1) Whatever.

    2) Can you give me a simple example?Let's say that i want to update cells from column 2 or move-cut the value from cell in column 2 to cell in column 1.

    3) Can @allan or @colin provide me with an example?
    May i use readtable to load data to the Datatable from a view (my complex query) and below that code use the classic serverside "sql" code that Editor uses?

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    You can indeed use a ViEW with Editor's server-side libraries to read more complex information that it attempts to set. There is an example of that here - the .NET download package has a same example in C#.

    Allan

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    I am a little bit confused on how to use view in Editor properly.

    1) In ->field( Do i have to use the fields from ->readtable view?Or the fields from the table i want to edit in Editor?
    2) How do relate the fields ->field( , left joins ->leftJoin( and filter ->where in Editor with the view from ->readtable

    I get the error The multi-part identifier... for many fields.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    1) You can do both. If you want a field from the read table only use:

    Field::inst('myField')->set(false)
    

    For write only fields:

    Field::inst('myField')->get(false)
    

    2) It should just be like normal. Can you show me the full code and error?

    Allan

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    1) If i am not mistaken about the use of VIEW in Editor script,i can use the readtable to load the data from the view in the Datatable?Am i correct?

    2) I currently load data to the Datatable from a php script with classic SQL code (no Editor style SQL code).Is it the same as using a VIEW in Editor style SQL code?What is the difference?

    3) Below-After the readtable command, the Fields that i will use ,will be the Editor Fields,i mean these fields have nothing to do with the columns loaded in the Datatable.

    4) How can i have 2 different instances of Editor in the same serverside php script?If this is possible,how will i call-use each Editor in the client side since the ajax url will be the same??

    Thanks again.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    1) Correct. See the example here.

    2) It might be the same if you are reading from the same VIEW and reading the same columns. From DataTables point of view, it doesn't really "care" where you get the data from or how, as long as it is presented with data.

    3) No, the fields will define all of the fields that the Editor (PHP) instance knows about. They might be read/write, read only or write only as described above.

    4) You'd just create two instances with two calls to Editor::inst() (or new Editor() if you prefer that style). However, you'd need to be careful about what data you feed them and what you expect to get back. For example you couldn't just call ->json() on both of them since that would be two JSON blobs which isn't valid JSON!

    Allan

This discussion has been closed.