l_sort function明细 netsuite列排序-CarlZeng
function l_sort(col,coltype,hier,hiercol,mach,colname,sAlternateSortType)153{154 // this is used in cases where a column needs to be sorted by something different than it’s type/value155 if(sAltern…
function l_sort(col,coltype,hier,hiercol,mach,colname,sAlternateSortType)
153{
154 // this is used in cases where a column needs to be sorted by something different than it’s type/value
155 if(sAlternateSortType != null)
156 coltype = sAlternateSortType;
157 var i = 0, node,node2, numRows = 0, rnode, col2 = -1, col2type;
158 var elems = new Array(), elem, cols;
159 var dir_up = true, dir_up2;
160 var ordered_mach = false;
161 if (mach == ‘’ || mach == null) mach = ‘’;
162 else if (document.forms[0].elements[mach+’sortidx’] != null)
163 {
164 col2 = document.forms[0].elements[mach+’sortidx’].value;
165 if (col2 == col)
166 col2 = -1;
167 else
168 {
169 col2type = document.forms[0].elements[mach+’sorttype’].value;
170 dir_up2 = document.forms[0].elements[mach+’sortdir’].value == “UP”;
171 }
172 ordered_mach = hasEncodedField(mach,mach+”seqnum”);
173 }
174
175 node = l_id(mach+’dir’+col);
176 if (node.src.indexOf(‘nlup.gif’) != -1)
177 dir_up = false;
178 node.src = dir_up ? ‘/images/nav/nlup.gif’ : ‘/images/nav/nldown.gif’;
179 node2 = l_id(mach+’header’);
180 for (idx=0; idx < node2.cells.length; idx++)
181 {
182 if (idx == col)
183 continue;
184 node = l_id(mach+’dir’+idx);
185 if (node != undefined)
186 node.src = ‘/images/nav/nlempty.gif’;
187 }
188
189 while (true)
190 {
191 node = l_id(mach+’row’+i);
192 if (node != undefined)
193 {
194 // when we are sorting by a different type/value than the cell contiains, that value will
195 // exist in a hidden span - which will always be the first child within the
196 if(sAlternateSortType != null)
197 elem = node.cells[col].firstChild.innerHTML;
198 else
199 elem = node.cells[col].innerHTML;
200 cols = new Array();
201
202 for (idx=0; idx < node.cells.length; idx++)
203 {
204 cols[idx] = node.cells[idx].innerHTML;
205
206 if(node.cells[idx].firstChild && node.cells[idx].firstChild.nodeName == ‘INPUT’ && node.cells[idx].firstChild.type == ‘checkbox’)
207 {
208 // If a checkbox is checked now, but was not checked the last time we drew it, add CHECKED to the input tag
209 if(node.cells[idx].firstChild.checked && node.cells[idx].innerHTML.indexOf(‘checked’) < 0)
210 cols[idx] = cols[idx].substring(0,cols[idx].length-1) + ‘ CHECKED>’;
211 // else if a checkbox is NOT checked, but it was when we drew it, remove CHECKED from the input tag
212 else if(!node.cells[idx].firstChild.checked && node.cells[idx].innerHTML.indexOf(‘checked’) >= 0)
213 cols[idx] = cols[idx].substring(0,cols[idx].indexOf(‘checked’)) + ‘>’;
214 }
215
216 }
217
218
219 if (hier)
220 {
221 hierfld = l_elem(‘_hier’+i);
222 if (hiercol)
223 elem = hierfld.value;
224 elems[i] = new l_node(elem.toLowerCase(),cols,coltype,dir_up,hierfld.value);
225 }
226 else if (col2 != -1)
227 elems[i] = new l_node(elem.toLowerCase(),cols,coltype,dir_up,null,node.cells[col2].innerHTML,col2type,dir_up2, ordered_mach ? findEncodedValue(mach, mach+”seqnum”, i+1) : -1);
228 else
229 elems[i] = new l_node(elem.toLowerCase(),cols,coltype,dir_up,null,null,null,null,ordered_mach ? findEncodedValue(mach, mach+”seqnum”, i+1) : -1);
230 i++;
231 }
232 else
233 break;
234 }
235
236 numRows = i;
237 i = 0;
238
239 elems.sort(l_sortnodes);
240
241 while (i < numRows)
242 {
243 node = l_id(mach+’row’+i);
244 rnode = elems[i];
245 cols = rnode.row;
246
247 for (idx=0; idx < node.cells.length; idx++)
248 node.cells[idx].innerHTML = cols[idx];
249
250 if (hier)
251 {
252 hierfld = l_elem(‘_hier’+i);
253 hierfld.value = rnode.hier;
254 }
255 if (ordered_mach)
256 setEncodedValue(mach,rnode.linenum,mach+’seqnum’,i+1);
257 i++;
258 }
259 l_saveprefs(mach, col, colname, coltype, dir_up);
260}
261
262function l_sortprefs(col,coltype,mach,colname)
263{
264 var dir_up = true;
265 node = l_id(mach+’dir’+col);
266 if (node.src.indexOf(‘nlup.gif’) != -1)
267 dir_up = false;
268 l_saveprefs(mach, col, colname, coltype, dir_up);
269}
270