Data render search unknown field error

Data render search unknown field error

veryjacksonveryjackson Posts: 19Questions: 5Answers: 0
{ data: null, render: function ( data, type, row ) {
                    var mot= data.cicekci.mottan+' '+data.cicekci.motta;
                    return type === 'display' && mot.length > 50 ?
                    mot.substr( 0, 50 ) +'…' :
                    mot;
                } }

I have like this code i search in internet but i cant find answer when i use data null have error unknown field

 { data: null, render: function ( data, type, row ) {
                // Combine the first and last names into a single table field
                return data.first_name+' '+data.last_name;
            } }

Example have same code its working but my code not working ???

Thank you

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    I don't see any issues with your code. Maybe you can post your DataTables initialization config for review.

    Kevin

  • veryjacksonveryjackson Posts: 19Questions: 5Answers: 0
    var table = $('#main').DataTable( {
                processing: true,
                ajax: {
                    url: "action.php",
                    type: 'POST'
                },
                serverSide: true,
                "order": [[0, 'desc']],
                columns: [
                    { data: "cicekci.id" },
                    { data: "u.username" },             
                                    { data: "cicekci.sid" },
                    { data: "cicekci.sandning" },
                    { data: null, render: function ( data, type, row ) {
                        var mot= data.cicekci.mottan+' '+data.cicekci.motta;
                        return type === 'display' && mot.length > 50 ?
                        mot.substr( 0, 50 ) +'…' :
                        mot;
                    } },
                    { data: null, render: function ( data, type, row ) {
                        return type === 'display' && data.cicekci.ovrig.length > 50 ?
                        data.cicekci.ovrig.substr( 0, 50 ) +'…' :
                        data.cicekci.ovrig;
                    } },
                    { data: "cicekci.levan" },
                    { data: "cicekci.id" }
                ],
                "columnDefs": [{
                    "targets": 7,
                    searchable: false,
                    orderable: false,
                    "data": "cicekci.id",
                    "render": function ( data, type, full, meta ) {
                      var aksiyon = '<center><button class="btn btn-info btn-sm" onClick="loadiframe(\'preview/' + data + '\')" data-toggle="modal" data-target="#korsedelmodal" data-title="Förhandsvisning" data-content=""><i class="glyphicon glyphicon-eye-open" aria-hidden="true"></i></button> <button class="btn btn-primary btn-sm" onClick="location.href=\'print/' + data + '\'" data-title="Skriva ut" data-content=""><i class="glyphicon glyphicon-print" aria-hidden="true"></i></button></center>';
                      return aksiyon
                    }
                  } ]
            } );
    

    my full code like this

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Could you also post your JSON data please. If you could post a link to the page showing the issue that would give us all the information required up front.

    Allan

  • veryjacksonveryjackson Posts: 19Questions: 5Answers: 0

    {"fieldErrors":[],"error":"ok\u00e4nt omr\u00e5de: (index 4)","data":[],"ipOpts":[],"cancelled":[]}

    my error json data

    {"data":[{"DT_RowId":"row_2169","cicekci":{"id":"2169","sid":"560","cid":"6","sandning":"Paket","dorr":"1","mottan":"Mimmi S\u00e4ll","motta":"KRONF\u00c5GEL AB\nFranz\u00e9ngatan 5\n11251 Kungsholmen","ovrig":"Levereras senast kl. 09.30\nPortkod: 4573","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"kungsholmen"}},{"DT_RowId":"row_2168","cicekci":{"id":"2168","sid":"488","cid":"3","sandning":"Begravning","dorr":"","mottan":"Per Berg","motta":"Danderyds Kyrka\nKl.13,00\/14,00","ovrig":"KORT:\nSov gott Per\nStefan &amp; Anna-Clara med familjer","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"hornan"}},{"DT_RowId":"row_2167","cicekci":{"id":"2167","sid":"487","cid":"3","sandning":"Begravning","dorr":"","mottan":"Per Berg","motta":"Danderyds kyrka\nKl.13,00\/14,00","ovrig":"KORT:\nMinns dig med v\u00e4rme Anna Johansson Maria, Sofia &amp; Elin","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"hornan"}},{"DT_RowId":"row_2166","cicekci":{"id":"2166","sid":"500","cid":"2","sandning":"Paket","dorr":"1","mottan":"Stefan Karpe","motta":"V\u00e4pplingev\u00e4gen 78\nT\u00e4by\n\ntel 070250788","ovrig":"Om m\u00f6jligt leverans vid ca 15-16","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"taby"}},{"DT_RowId":"row_2165","cicekci":{"id":"2165","sid":"486","cid":"3","sandning":"Begravning","dorr":"","mottan":"Per Berg","motta":"Danderyds kyrka\nKl.13,00\/14,00","ovrig":"KORT:\nEn sista h\u00e4lsning fr\u00e5n kusinerna Mie, Ulla &amp; Nils-Axel","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"hornan"}},{"DT_RowId":"row_2164","cicekci":{"id":"2164","sid":"499","cid":"2","sandning":"Paket","dorr":"","mottan":"Novartis","motta":"best\u00e4llare Anna-Lena Jorring\nf\u00f6r avtackning f\u00f6r Anna-Lena Engwall\n\nKemsistv \nT\u00e4by","ovrig":"F\u00d6RMIDDAG!!!","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"taby"}},{"DT_RowId":"row_2163","cicekci":{"id":"2163","sid":"498","cid":"2","sandning":"Paket","dorr":"1","mottan":"Jonas Persson","motta":"Vallarev\u00e4gen 13\nT\u00e4by\n\ntel 070166005","ovrig":"F\u00d6RE KL 10.30!!!","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"taby"}},{"DT_RowId":"row_2162","cicekci":{"id":"2162","sid":"559","cid":"6","sandning":"Paket","dorr":"1","mottan":"SKANDIA ","motta":"Ekedalsgatan 9\nKungsholmen","ovrig":"Levereras senast kl. 08.45","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"kungsholmen"}},{"DT_RowId":"row_2161","cicekci":{"id":"2161","sid":"558","cid":"6","sandning":"Paket","dorr":"1","mottan":"Visma Azets","motta":"Lindhagensgatan 94\nKungsholmen","ovrig":"Levereras senast kl. 11.00","levan":"22-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"kungsholmen"}},{"DT_RowId":"row_2160","cicekci":{"id":"2160","sid":"485","cid":"3","sandning":"Paket","dorr":"1","mottan":"Pirjo Axelsson Johnson","motta":"Skogsslingan 8 1tr\nDanderyd\n08 755 90 61","ovrig":"PK 0872\n","levan":"21-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"hornan"}},{"DT_RowId":"row_2159","cicekci":{"id":"2159","sid":"484","cid":"3","sandning":"Paket","dorr":"1","mottan":"Birgit Andersson","motta":"M\u00f6rbyh\u00f6jden 8 3tr\nDanderyd\n070 230 44 08","ovrig":"PK7088","levan":"21-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"hornan"}},{"DT_RowId":"row_2158","cicekci":{"id":"2158","sid":"557","cid":"6","sandning":"Paket","dorr":"1","mottan":"Atousa Wikstr\u00f6m","motta":"Fimbulv\u00e4gen 3\n18263 Djursholm\nTele: 0761660707","ovrig":"F\u00e5r l\u00e4mnas vid d\u00f6rren!","levan":"21-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"kungsholmen"}},{"DT_RowId":"row_2157","cicekci":{"id":"2157","sid":"483","cid":"3","sandning":"Paket","dorr":"","mottan":"Elvira Grahn","motta":"Krukmakargatan 35D\n118 51 Stockholm\n070 070 68 26","ovrig":"Porttelefon","levan":"21-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"hornan"}},{"DT_RowId":"row_2156","cicekci":{"id":"2156","sid":"556","cid":"6","sandning":"Paket","dorr":"1","mottan":"David Kummel","motta":"P-O Hallmans gata 3\nKungsholmen\nTele: 0709600104","ovrig":"Portkod: 9631 OK\nF\u00e5r l\u00e4mnas vid d\u00f6rren","levan":"21-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"kungsholmen"}},{"DT_RowId":"row_2155","cicekci":{"id":"2155","sid":"497","cid":"2","sandning":"Paket","dorr":"","mottan":"Marianne Norrg\u00e5rd","motta":"Novartis","ovrig":"","levan":"21-03-2017","sonduzenleyen":"","datum":"2017-03-21","datum2":""},"u":{"username":"taby"}}],"options":[],"files":[],"draw":1,"recordsTotal":"2169","recordsFiltered":"2169"}

    and my normal json data

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    I noticed you have "files":[] in the JSON response. Not sure if that is the source of the unknown field error. 'files` is not one of the required or optional fields that server side is expecting.

    You can validate your code works with your data by creating a data variable containing the data object, remove the ajax and serverside config and add data: data into the DataTables init.

    For example:

    var data = [{
            "DT_RowId": "row_2169",
            "cicekci": {
                "id": "2169",
                "sid": "560",
                "cid": "6",
                "sandning": "Paket",
                "dorr": "1",
                "mottan": "Mimmi S\u00e4ll",
                "motta": "KRONF\u00c5GEL AB\nFranz\u00e9ngatan 5\n11251 Kungsholmen",
                "ovrig": "Levereras senast kl. 09.30\nPortkod: 4573",
                "levan": "22-03-2017",
                "sonduzenleyen": "",
                "datum": "2017-03-21",
                "datum2": ""
            },
            "u": {
                "username": "kungsholmen"
            }
        }, 
    .......
    ]
    

    Allan may find something else in the JSON but if not a link to a page showing the issue is needed.

    Kevin

  • veryjacksonveryjackson Posts: 19Questions: 5Answers: 0

    and giving an error when i searching normaly working I had to say it at first sorry

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Could you show us the exact error message please?

    It really would save us all a lot of time if you could link to the page so we could get this information immediately.

    Thanks,
    Allan

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    I see you've actually sent me the link by PM - thanks.

    Okay - so the error message is:

    DataTables warning: table id=main - okänt område: (index 4)
    

    which happens when you type a character into the DataTables global search box.

    That appears to translate as "unknown area: (index 4)".

    What does your action.php script contain please?

    Allan

  • veryjacksonveryjackson Posts: 19Questions: 5Answers: 0

    I send you my action.php code with pm

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Thank you. The issue is that you are using server-side processing, but two of your columns have columns.data set to be null and instead use client-side generated data.

    With server-side processing obviously you can't search or sort client-side generated data, so you need to select one of:

    Allan

  • veryjacksonveryjackson Posts: 19Questions: 5Answers: 0

    Thank you I found a solution with getFormatter

  • ManuelWennerManuelWenner Posts: 16Questions: 2Answers: 1

    @allan I tried it by disabling search and sort on those columns but it's not working. I need server-side processing cause it's about 100.000 entries. What do you mean by split the data into multiple columns?

    @veryjackson
    How did you fix this?

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    @ManuelWenner - If you link to your page I can take a look at it.

    What I meant by splitting the data was that rather than having null data and client-side generating values from another more complex column, have the data you want in the columns which are currently null. It is not clear to me that advice would apply in your situation, since I don't know much about your specific case!

    Allan

This discussion has been closed.