javascript - Why don't jquery datatable get filled with newly updated data after searching? -




i filling jquery datatable (ver: 1.10.15) webapi , works when search in datatable via searchbox doesn't fill datatable updated data. why?

i checked, sends search value , brings updated data server doesn't populate table newly returned data.

function show() {                                  $('#example').datatable({ //  "processing": true,     "serverside": true,     "retrieve": true,     "destroy": true,     "pagination": true, //  "contenttype": 'application/json; charset=utf-8',     "ajax": "http://localhost:28071/users"   }); } 

update:

c# api code:

namespace webapihimher.controllers {     public class userscontroller : apicontroller     {         [httpget]         public dtresult getdata([fromuri]dtparameters v)         {              list<string[]> s = new list<string[]>();              //list<basicoperations> s = new list<basicoperations>();              basicoperations bo= new basicoperations();               s = bo.getusers(v.length, v.start, 1, v.sortorder, v.search.value);              dtresult r = new dtresult();             r.draw = 1;             r.recordsfiltered = s.count;             r.recordstotal = 100; ;             r.data = s;              return r;         }     }      public class dtresult     {         public int draw { get; set; }         public int recordstotal { get; set; }         public int recordsfiltered { get; set; }         public list<string[]> data { get; set; }     }     public abstract class dtrow     {         public virtual string dt_rowid         {             { return null; }         }         public virtual string dt_rowclass         {             { return null; }         }         public virtual object dt_rowdata         {             { return null; }         }     }     public class dtparameters     {         public int draw { get; set; }         public dtcolumn[] columns { get; set; }         public dtorder[] order { get; set; }         public int start { get; set; }         public int length { get; set; }         public dtsearch search { get; set; }         public string sortorder         {                         {                 return columns != null && order != null && order.length > 0                     ? (columns[order[0].column].data + (order[0].dir == dtorderdir.desc ? " " + order[0].dir : string.empty))                     : null;             }         }     }     public class dtcolumn     {         public string data { get; set; }         public string name { get; set; }         public bool searchable { get; set; }         public bool orderable { get; set; }         public dtsearch search { get; set; }     }     public class dtorder     {         public int column { get; set; }         public dtorderdir dir { get; set; }     }     public enum dtorderdir     {         asc,         desc     }     public class dtsearch     {         public string value { get; set; }         public bool regex { get; set; }       }  } 

i posting request , response after initial table load , after performing search

after initial load:

  • request:

_ 1503560388132 columns[0][data] 0 columns[0][name] columns[0][orderable] true columns[0][search][regex] false columns[0][search][value] columns[0][searchable] true columns[1][data] 1 columns[1][name] columns[1][orderable] true columns[1][search][regex] false columns[1][search][value] columns[1][searchable] true draw 2 length 10 order[0][column] 0 order[0][dir] asc search[regex] false search[value] 2 start 0

response:

{"draw":1,"recordstotal":4,"recordsfiltered":25,"data":[["hunain","123"],["hk","asd"],["daenerys targaryen" ,"123"],["",""]]}

after performing search:

  • request:

_ 1503560409319 columns[0][data] 0 columns[0][name] columns[0][orderable] true columns[0][search][regex] false columns[0][search][value] columns[0][searchable] true columns[1][data] 1 columns[1][name] columns[1][orderable] true columns[1][search][regex] false columns[1][search][value] columns[1][searchable] true draw 2 length 10 order[0][column] 0 order[0][dir] asc search[regex] false search[value] w start 0

  • response:

{"draw":1,"recordstotal":1,"recordsfiltered":25,"data":[["waleed","123"]]}

the reason draw parameter being sent , received not same because took draw static in server code mismatched. returned same draw parameter sent.


from docs :

the draw counter object response - draw parameter sent part of data request. note recommended security reasons cast parameter integer, rather echoing client sent in draw parameter, in order prevent cross site scripting (xss) attacks.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -