Handling null Values

Handling null Values

rangaranga Posts: 31Questions: 12Answers: 2
edited July 2018 in Free community support

Hi All

I have a serialized json string like this.

[[null,null,null,null,null],[null,"Rough Costing",null,null,null],[null,null,null,null,null],[null,"Client","Ua Limited",null,null],[null,"Product",null,null,null],[null,"Pro: Name","Idam ",null,null],[null,"Est.: No",null,null,null],[null,"Time: period  ","43299",null,null],[null,"Date","15th July - 2018",null,null],[null,null,null,null,null]] 

this was a json conversion of csv file generated from a excel invoice file and my aim is to load the csv to datatable and let the users to get rid of the unwanted rows containing headings and section names and save the values to db.

but as you can see this string contains lots of nulls and no column names. and the table is in loading mode and cant see any relevant jquery error.

is this array valid for datatables with null values. is there any specific way to load this?

now im here but no much different even without column definitions.

`$(document).ready(function () {
     $('#example').DataTable({
            dom: "Bfrtip",
            ajax: "/POPM_Trn_IOU/ExportToExcel",
            "columns": [
                {
                    "data": 0, 
                    "defaultContent": ""
                },
                {
                    "data": 1, 
                    "defaultContent": ""
                },
                {
                    "data": 2,
                    "defaultContent": ""
                },
                {
                    "data": 3, 
                    "defaultContent": ""
                },
                {
                    "data": 4, 
                    "defaultContent": ""
                }
            ],
            dataSrc: ""  
            
    });  
    });

Thank You

This question has an accepted answers - jump to answer

Answers

  • Bindrid2Bindrid2 Posts: 79Questions: 4Answers: 12

    http://live.datatables.net/regeveho/1/edit is a simple table based on your data. It works.

    dataSrc should be in your ajax:
    ajax:{ url:"/POPM_Trn_IOU/ExportToExcel", dataSrc: "" }

  • rangaranga Posts: 31Questions: 12Answers: 2

    @Bindrid2 Thanks mate. i gt through with it. but now the issue is datatable in my mvc application takes all the data to fill the first column only. its like cos of no column definitions. any idea ?

  • allanallan Posts: 62,109Questions: 1Answers: 10,183 Site admin

    The JSON being returned must be in a different format. If you could like to a page showing the issue, that would be useful. Otherwise, please use the debugger's upload option to let me see the data.

    Allan

  • rangaranga Posts: 31Questions: 12Answers: 2

    @Allan the problem here what im not understanding is the data works here but the same data not working in my real application . yes there were warnings "Requested unknown parameter '1' for row 0, column 1" but default content took care of it

    but data is actually vertical

    and this is what debugger uploaded configuration details https://debug.datatables.net/aderol

    I can edit the original data array to have column names but guess that wont be a good approach .

  • rangaranga Posts: 31Questions: 12Answers: 2

    @Allan

    i use jsonconvert.serialized( 2darray) to convert my 2D array to 1D json array.
    but since it serialized as
    "[[null,null,null,null,null],[null,"Rough Costing",null,null,null]]"
    ( with double quotes surrounding)
    that makes datatables to take it as a one object and only filled the first column.
    i tried deserializing it again but this time it surrounded with curly braces . like
    {[[null,null,null,null,null],[null,"Rough Costing",null,null,null]]} again not a format for datatables. (according to this http://live.datatables.net/regeveho/5/edit)
    i tried trimming and replacing but seems the double quotes are coming from json.

    is there any way i can format this within datatables function
    like `"ajax": {
    "url": "/POPM_Trn_IOU/ExportToExcel",

            "type": 'GET',
            success function (..............)
               return ........
        ],`
    

    Thank you

  • allanallan Posts: 62,109Questions: 1Answers: 10,183 Site admin
    Answer ✓

    The debugger show no tables I'm afraid. That usually means that there was a Javascript error while the table was initialised. I'm afraid I'd need a link to a page showing the issue to be able to offer any help.

    ALlan

  • rangaranga Posts: 31Questions: 12Answers: 2

    @Allan issue was i used
    Json(JsonConvert.SerializeObject(symboltable2), JsonRequestBehavior.AllowGet);
    to serialized and return the object which cause double serialized the object.

    return Content(JsonConvert.SerializeObject(symboltable2), "application/json"); with actionresults worked fine.

    Thank you for your consideration .

This discussion has been closed.