several datatables inside bootstrap tabs

several datatables inside bootstrap tabs

wijwijwijwij Posts: 52Questions: 11Answers: 0

Hi
I will appreciate if you can help me with the problem, I am having right now with my datatables
Scenario:
I have 4 bootstrap tabs
Inside each tab there is a datatable and editor
All the tables are sharing the same table “products”, but the difference is that I have 4 different controllers: controller for each table in the 4 tabs where I am using “When” to filter and fetch the data based on the status value [sample controller is following - line 20 is where I change the proce value]

Tab1 datatable get data from products table when status=0
Tab2 datatatble get data from products table when status =1
Tab3 datatatble get data from products table when status =S
Tab4 datatatble get data from products table when status =Q

I have editor submit button above each datatable

in tab1: when click the submit then status should change 0 to 1
in tab2: when click the submit then status should change 1 to S
in tab3: when click the submit then status should change S to Q
in tab4: when click the submit then status should change A to C

If I have only one datatable in tab1 and no other tables exist, then the submit button works just fine
The problem happened when I add datatable in tab2; then the submit button will work in tab2 but no in tab 1.
If I add datatable in tab3 then submit button works in tab3 but not in tab 2 and so on

sample controller is here:

                    public class ProductsController : ApiController
                        {
                            [Route("api/products")]
                            [HttpGet]
                            [HttpPost]
                            public IHttpActionResult Products()
                            {
                                var request = HttpContext.Current.Request;
                                var settings = Properties.Settings.Default;

                                using (var db = new Database(settings.DbType, settings.DbConnection))
                                {
                                    var response = new Editor(db, "Product")
                                       .Field(new Field("id").Validator(Validation.NotEmpty()))
                                       .Field(new Field("ProductID").Validator(Validation.NotEmpty()))
                                       .Field(new Field("ProdDesc").Validator(Validation.NotEmpty()))
                                       .Field(new Field("Origin").Validator(Validation.NotEmpty()))
                                       .Field(new Field("proce").Validator(Validation.NotEmpty()))

                                       .Where("proce", "0") //get the unprocessed Prod only

                                       .MJoin(new MJoin("ProductPack")

                                       .Link("Product.ProductID", "Pack.PrdID")
                                       .Field(new Field("Pack.id"))
                                       .Field(new Field("Pack.ProdID"))
                                       .Field(new Field("Pack.Cat"))
                                       .Field(new Field("Pack.Cap"))                    )
                                       .Process(request)
                                       .Data();
                                    return Json(response);              
                                }
                            }
                        }

I am not sure where is error is: But I believe it is because I am using the same table. Or I may be mistaken

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Its hard to say without seeing the running code. Please post a link to your page or a test case showing the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    in tab1: when click the submit then status should change 0 to 1

    Is the submit button in one of the editor forms or a custom form you created?

    Is the data sent to the server?

    Do you get errors in the browser's console?

    What troubleshooting steps have you taken?

    Kevin

  • wijwijwijwij Posts: 52Questions: 11Answers: 0

    Hi Kevin,

    It is hard to post a test case because it is a really long one. I tried to simplify it as much as I can just to pass the idea to you

    The moment I hit the submit button; the column "proce" value changed from 0 to 1 in the database. But only when no other datatable present

    In term of troubleshooting, I have used the developer window in the firefox browser where it enables me to see the post result from the server (200, 500, or 404)

    The error I got is always referring to the controller which called by the second datatable

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    Answer ✓

    The error I got is always referring to the controller which called by the second datatable

    What is the error?

    The problem happened when I add datatable in tab2; then the submit button will work in tab2 but no in tab 1.

    What exactly happens?

    What is shown in the ajax request and response when tab 1 doesn't work?

    Without seeing what you are doing on the Javascript side it will be very difficult to offer suggestions.

    Kevin

  • wijwijwijwij Posts: 52Questions: 11Answers: 0
    edited March 2021

    Thanks, Kevin,

    I found that this line:

    window.editor = myEditor;

    is the cause of the problem. Once I commented it out; everything works fine!

This discussion has been closed.