@@ 66-97 (lines=32) @@ | ||
63 | return params |
|
64 | ||
65 | ||
66 | def create_dt_params_with_mData_shuffled( |
|
67 | columns, search="", start=0, length=10, order=None |
|
68 | ): |
|
69 | """Create DataTables input parameters when the data source from the rows |
|
70 | data object/ array is set. Also when the order in the frontend is not same |
|
71 | as in the backend. |
|
72 | ||
73 | Read more about setting column data source here https://datatables.net/reference/option/columns.data""" |
|
74 | ||
75 | params = { |
|
76 | "draw": "1", |
|
77 | "start": str(start), |
|
78 | "length": str(length), |
|
79 | "search[value]": str(search), |
|
80 | "search[regex]": "false", |
|
81 | } |
|
82 | # Shuffle the columns in place |
|
83 | shuffle(columns) |
|
84 | for i, item in enumerate(columns): |
|
85 | cols = "columns[%s]" % i |
|
86 | params["%s%s" % (cols, "[data]")] = item.mData |
|
87 | params["%s%s" % (cols, "[name]")] = "" |
|
88 | params["%s%s" % (cols, "[searchable]")] = "true" |
|
89 | params["%s%s" % (cols, "[orderable]")] = "true" |
|
90 | params["%s%s" % (cols, "[search][value]")] = "" |
|
91 | params["%s%s" % (cols, "[search][regex]")] = "false" |
|
92 | ||
93 | for i, item in enumerate(order or [{"column": 0, "dir": "asc"}]): |
|
94 | for key, value in item.items(): |
|
95 | params["order[%s][%s]" % (i, key)] = str(value) |
|
96 | ||
97 | return params |
|
98 | ||
99 | ||
100 | def create_dt_params_with_mData_with_extra_data( |
|
@@ 36-63 (lines=28) @@ | ||
33 | # These methods would only be used when the mData param is defined in the backend |
|
34 | ||
35 | ||
36 | def create_dt_params_with_mData(columns, search="", start=0, length=10, order=None): |
|
37 | """Create DataTables input parameters when the data source from the rows |
|
38 | data object/ array is set. |
|
39 | ||
40 | Read more about setting column data source here https://datatables.net/reference/option/columns.data""" |
|
41 | ||
42 | params = { |
|
43 | "draw": "1", |
|
44 | "start": str(start), |
|
45 | "length": str(length), |
|
46 | "search[value]": str(search), |
|
47 | "search[regex]": "false", |
|
48 | } |
|
49 | ||
50 | for i, item in enumerate(columns): |
|
51 | cols = "columns[%s]" % i |
|
52 | params["%s%s" % (cols, "[data]")] = item.mData |
|
53 | params["%s%s" % (cols, "[name]")] = "" |
|
54 | params["%s%s" % (cols, "[searchable]")] = "true" |
|
55 | params["%s%s" % (cols, "[orderable]")] = "true" |
|
56 | params["%s%s" % (cols, "[search][value]")] = "" |
|
57 | params["%s%s" % (cols, "[search][regex]")] = "false" |
|
58 | ||
59 | for i, item in enumerate(order or [{"column": 0, "dir": "asc"}]): |
|
60 | for key, value in item.items(): |
|
61 | params["order[%s][%s]" % (i, key)] = str(value) |
|
62 | ||
63 | return params |
|
64 | ||
65 | ||
66 | def create_dt_params_with_mData_shuffled( |
|
@@ 4-30 (lines=27) @@ | ||
1 | from random import shuffle |
|
2 | ||
3 | ||
4 | def create_dt_params(columns, search="", start=0, length=10, order=None): |
|
5 | """Create DataTables input parameters when the data source from the rows |
|
6 | data object/ array is not set. |
|
7 | ||
8 | Read more about setting column data source here https://datatables.net/reference/option/columns.data""" |
|
9 | params = { |
|
10 | "draw": "1", |
|
11 | "start": str(start), |
|
12 | "length": str(length), |
|
13 | "search[value]": str(search), |
|
14 | "search[regex]": "false", |
|
15 | } |
|
16 | ||
17 | for i, item in enumerate(columns): |
|
18 | cols = "columns[%s]" % i |
|
19 | params["%s%s" % (cols, "[data]")] = i |
|
20 | params["%s%s" % (cols, "[name]")] = "" |
|
21 | params["%s%s" % (cols, "[searchable]")] = "true" |
|
22 | params["%s%s" % (cols, "[orderable]")] = "true" |
|
23 | params["%s%s" % (cols, "[search][value]")] = "" |
|
24 | params["%s%s" % (cols, "[search][regex]")] = "false" |
|
25 | ||
26 | for i, item in enumerate(order or [{"column": 0, "dir": "asc"}]): |
|
27 | for key, value in item.items(): |
|
28 | params["order[%s][%s]" % (i, key)] = str(value) |
|
29 | ||
30 | return params |
|
31 | ||
32 | ||
33 | # These methods would only be used when the mData param is defined in the backend |