Data lost between front and DB

Data lost between front and DB

drodro Posts: 3Questions: 1Answers: 0

I've a list of queries in DB with two types who fill two datatables. In the second one, i've some visits link by a fk_visit_id to a visit table and some visitType link by a fk_visit_type_id to a visitType table, the both table have some fk too.

When i call my ajax to fill my second datatable like this :

                var options = {
                            name : "queriesOustandingDate",
                            language : {
                                "infoFiltered": ""
                              },
                            paging : true,
                            lengthChange : true,
                            paginationType : "full_numbers",
                            columnsSearching : true,
                            serverSide: true,
                            createdRow: onRowCreated,
                            ajax : {
                                url : "../services/supervision/queries/oustandingDate/list?protocolId=" + mProtocolId,
                                data: function(data, settings) {
                                    // Add data when request is sent to the API
                                    const merged = data.columns.map(function(item, i) {
                                        if (columnOustandingDateDefinitions[i].search)
                                            item.search = $.extend(true, {}, item.search, columnOustandingDateDefinitions[i].search);
                                        return item;
                                    });
                                    data.columns = merged;
                                },
                                complete : function(json){
                                    listOfQueries=json.responseJSON.data;
                                    console.log("---------------- listOfQueries Oustanding -----------------", listOfQueries);
                                }
                            },
                            columns : columnOustandingDateDefinitions,
                            order : [ [ 9, 'asc' ], [ 8, 'asc' ] ]
                        };
                        queriesOustandingDateTable = new RawDataTable(options);
                    }

My datatable is fill like this and you can see the column Visit Type empty but i've some info in DB !!! :

And if i modify the sorting by Subject for example, some Visit Type are displayed !!!

Thx all !

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    Can you show us the JSON response from the server please?

    Allan

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Use the browser's network inspector tool to see what is in the JSON response for the XHR request. Verify there is data for the Visit Type column.

    You have createdRow: onRowCreated,. The createdRow callback is used to manipulate the display output of each row. Take a look at the onRowCreated function to see what it is doing.

    Let us know what you find.

    Kevin

  • drodro Posts: 3Questions: 1Answers: 0
    edited November 2022

    @allan : In my json, my VisitType object is null !

    @kthorngren : My onRowCreated just add some attr with id row by row !

    My return in my controller is ok, the object VisitType is complete but i lost my visitType between the DataTableResponse in my java and the return of ajax call...it's strange !
    I do this trick to resolve my problem but it's a little dirty^^

    Collection<Query> lQueries = mQueryDataTableDao.findPaginatedObjectByProtocol(lPaginatedQuery,
                        lPaginationCriteria.getPageNumber(), lPaginationCriteria.getPageSize());
                
                
                DataTableResponse<Query> lDataTableResponse = new DataTableResponse<Query>(lDataTableRequest);
    
                lDataTableResponse.setRecordsFiltered(mQueryDataTableDao.countFilteredObjectByProtocol(lPaginatedQuery));
                lDataTableResponse.setRecordsTotal(
                        mQueryDataTableDao.countAllObjectByProtocol(lDataTableRequest.getProtocolId(), Query.class, true));
                
                    for (Query lQuery : lQueries) {
                        // trick to resolve a display bug cause by othet entity relationship 
                        VisitType newVisitType = new VisitType();
                        newVisitType.setId(lQuery.getVisitType().getId());
                        newVisitType.setName(lQuery.getVisitType().getName());
                        lQuery.setVisitType(newVisitType);
                    }
                
                lDataTableResponse.setData(lQueries);
                            
                return lDataTableResponse;
    

    if i instance a new object with less entity relationship, it's ok !

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin
    Answer ✓

    I'm afraid that server-side support in Java is outside my range of competence. You'd need to ask on StackOverflow or a Java specific support forum.

    Good to know you've got a workaround though!

    Allan

  • drodro Posts: 3Questions: 1Answers: 0

    Thx for help ;)

Sign In or Register to comment.