UNPKG

38.1 kBMarkdownView Raw
1## Objects
2
3<dl>
4<dt><a href="#DataTable">DataTable</a> : <code>object</code></dt>
5<dd><p>前端数据模型对象</p>
6</dd>
7</dl>
8
9## Functions
10
11<dl>
12<dt><a href="#resetAllValue">resetAllValue()</a></dt>
13<dd><p>重置所有行的数据至nrm状态时的数据</p>
14</dd>
15<dt><a href="#resetValueByRow">resetValueByRow(row)</a></dt>
16<dd><p>根据row对象重置数据至nrm状态时的数据</p>
17</dd>
18</dl>
19
20<a name="DataTable"></a>
21
22## DataTable : <code>object</code>
23前端数据模型对象
24
25
26* [DataTable](#DataTable) : <code>object</code>
27 * _instance_
28 * [.id](#DataTable+id) : <code>string</code>
29 * [.strict](#DataTable+strict) : <code>boolean</code>
30 * [.meta](#DataTable+meta) : <code>object</code>
31 * [.enable](#DataTable+enable) : <code>boolean</code>
32 * [.pageSize](#DataTable+pageSize) : <code>number</code>
33 * [.pageIndex](#DataTable+pageIndex) : <code>number</code>
34 * [.totalPages](#DataTable+totalPages) : <code>number</code>
35 * [.pageCache](#DataTable+pageCache) : <code>boolean</code>
36 * [.params](#DataTable+params) : <code>object</code>
37 * [.master](#DataTable+master) : <code>string</code>
38 * [.dateNoConvert](#DataTable+dateNoConvert) : <code>boolean</code>
39 * _static_
40 * [.copyRow(index, row)](#DataTable.copyRow)
41 * [.copyRows(index, rows)](#DataTable.copyRows)
42 * [.setData(data, options)](#DataTable.setData)
43 * [.setValue(fieldName, value, [row], [ctx])](#DataTable.setValue)
44 * [.isEnable([fieldName])](#DataTable.isEnable) ⇒ <code>boolean</code>
45 * [.setEnable(enable)](#DataTable.setEnable)
46 * [.getCurrentRow()](#DataTable.getCurrentRow) ⇒ <code>null</code> &#124; <code>u.Row</code>
47 * [.getCurrentIndex()](#DataTable.getCurrentIndex) ⇒ <code>number</code>
48 * [.getData()](#DataTable.getData) ⇒ <code>array</code>
49 * [.getDataByRule(rule)](#DataTable.getDataByRule) ⇒ <code>array</code>
50 * [.getRow(index)](#DataTable.getRow) ⇒ <code>object</code>
51 * [.getRowByRowId(rowid)](#DataTable.getRowByRowId) ⇒ <code>Row</code>
52 * [.getRowIndex(需要获取索引的row对象)](#DataTable.getRowIndex) ⇒ <code>\*</code>
53 * [.getRowsByField(field, value)](#DataTable.getRowsByField) ⇒ <code>array</code>
54 * [.getRowByField(field, value)](#DataTable.getRowByField) ⇒ <code>u.Row</code>
55 * [.getAllRows()](#DataTable.getAllRows) ⇒ <code>array</code>
56 * [.getAllPageRows()](#DataTable.getAllPageRows) ⇒ <code>array</code>
57 * [.getChangedDatas(withEmptyRow)](#DataTable.getChangedDatas) ⇒ <code>array</code>
58 * [.getChangedRows()](#DataTable.getChangedRows) ⇒ <code>array</code>
59 * [.getValue(fieldName, [row])](#DataTable.getValue) ⇒ <code>string</code>
60 * [.getIndexByRowId(rowId)](#DataTable.getIndexByRowId)
61 * [.getAllDatas()](#DataTable.getAllDatas) ⇒ <code>array</code>
62 * [.getRowIdsByIndices(indices)](#DataTable.getRowIdsByIndices) ⇒ <code>array</code>
63 * [.getRowsByIndices(indices)](#DataTable.getRowsByIndices) ⇒ <code>array</code>
64 * [.getFocusRow()](#DataTable.getFocusRow) ⇒ <code>u.Row</code>
65 * [.getFocusIndex()](#DataTable.getFocusIndex) ⇒ <code>number</code>
66 * [.getMeta([fieldName], [key])](#DataTable.getMeta) ⇒ <code>object</code>
67 * [.getRowMeta([fieldName], [key])](#DataTable.getRowMeta) ⇒ <code>object</code>
68 * [.getParam(key)](#DataTable.getParam) ⇒ <code>\*</code>
69 * [.getSelectedIndex()](#DataTable.getSelectedIndex) ⇒ <code>number</code>
70 * [.getSelectedIndices()](#DataTable.getSelectedIndices) ⇒ <code>array</code>
71 * [.getSelectedDatas([withEmptyRow])](#DataTable.getSelectedDatas) ⇒ <code>array</code>
72 * [.getSelectedRows()](#DataTable.getSelectedRows) ⇒ <code>array</code>
73 * [.getSimpleData([options])](#DataTable.getSimpleData) ⇒ <code>array</code>
74 * [.setMeta(fieldName, key, value)](#DataTable.setMeta)
75 * [.updateMeta(meta)](#DataTable.updateMeta)
76 * [.addParam(key, value)](#DataTable.addParam)
77 * [.addParams(params)](#DataTable.addParams)
78 * [.refSelectedRows(fieldName)](#DataTable.refSelectedRows)
79 * [.ref(fieldName)](#DataTable.ref)
80 * [.refMeta(fieldName, key)](#DataTable.refMeta)
81 * [.refRowMeta(fieldName, key)](#DataTable.refRowMeta)
82 * [.refEnable(fieldName)](#DataTable.refEnable)
83 * [.removeRowByRowId(rowId)](#DataTable.removeRowByRowId)
84 * [.removeRow(index)](#DataTable.removeRow)
85 * [.removeAllRows()](#DataTable.removeAllRows)
86 * [.removeRows(indices)](#DataTable.removeRows)
87 * [.clear()](#DataTable.clear)
88 * [.addRow(row)](#DataTable.addRow)
89 * [.addRows(rows)](#DataTable.addRows)
90 * [.insertRow(index, row)](#DataTable.insertRow)
91 * [.insertRows(index, rows)](#DataTable.insertRows)
92 * [.createEmptyRow()](#DataTable.createEmptyRow) ⇒ <code>u.Row</code>
93 * [.setAllRowsSelect()](#DataTable.setAllRowsSelect)
94 * [.setRowSelect(index)](#DataTable.setRowSelect)
95 * [.setRowsSelect(indices)](#DataTable.setRowsSelect)
96 * [.addRowSelect(index)](#DataTable.addRowSelect)
97 * [.addRowsSelect(indices)](#DataTable.addRowsSelect)
98 * [.setAllRowsUnSelect([options])](#DataTable.setAllRowsUnSelect)
99 * [.setRowUnSelect(index)](#DataTable.setRowUnSelect)
100 * [.setRowsUnSelect(indices)](#DataTable.setRowsUnSelect)
101 * [.toggleAllSelect()](#DataTable.toggleAllSelect)
102 * [.setRowFocus(index, [quiet], [force])](#DataTable.setRowFocus)
103 * [.setRowUnFocus()](#DataTable.setRowUnFocus)
104 * [.setSimpleData(data, [options])](#DataTable.setSimpleData)
105 * [.addSimpleData(data, [status], [options])](#DataTable.addSimpleData)
106 * [.on(name, [callback], [one])](#DataTable.on) ⇒ <code>[DataTable](#DataTable)</code>
107 * [.off(name, [callback])](#DataTable.off) ⇒ <code>[DataTable](#DataTable)</code>
108 * [.one(name, [callback])](#DataTable.one)
109 * [.trigger(name)](#DataTable.trigger) ⇒ <code>[DataTable](#DataTable)</code>
110
111<a name="DataTable+id"></a>
112
113### dataTable.id : <code>string</code>
114DataTable对应的唯一标识
115
116<a name="DataTable+strict"></a>
117
118### dataTable.strict : <code>boolean</code>
119在设置数据时是否自动创建对应字段,如果为true则不自动创建,如果为false则自动创建缺失的字段
120
121**Default**: <code>false</code>
122<a name="DataTable+meta"></a>
123
124### dataTable.meta : <code>object</code>
125DataTable的所有字段属性信息
126
127<a name="DataTable+enable"></a>
128
129### dataTable.enable : <code>boolean</code>
130DataTable的是否支持编辑功能
131
132**Default**: <code>true</code>
133<a name="DataTable+pageSize"></a>
134
135### dataTable.pageSize : <code>number</code>
136DataTable支持翻页功能时每页显示数据条数
137
138**Default**: <code>20</code>
139<a name="DataTable+pageIndex"></a>
140
141### dataTable.pageIndex : <code>number</code>
142DataTable支持翻页功能时当前页码
143
144**Default**: <code>0</code>
145<a name="DataTable+totalPages"></a>
146
147### dataTable.totalPages : <code>number</code>
148DataTable支持翻页功能时总页数
149
150**Default**: <code>0</code>
151<a name="DataTable+pageCache"></a>
152
153### dataTable.pageCache : <code>boolean</code>
154DataTable的是否支持前端缓存,支持前端缓存则前端会存储所有页的数据信息,否则只保存当前页的数据信息。如果使用前端缓存则需要使用框架封装的fire方法来与后台进行交互
155
156**Default**: <code>false</code>
157<a name="DataTable+params"></a>
158
159### dataTable.params : <code>object</code>
160使用者自定义的属性合集,框架内部不会针对此属性进行特殊处理,仅用于设置及获取
161
162<a name="DataTable+master"></a>
163
164### dataTable.master : <code>string</code>
165使用者自定义的属性,框架内部不会针对此属性进行特殊处理,仅用于设置及获取。
166
167<a name="DataTable+dateNoConvert"></a>
168
169### dataTable.dateNoConvert : <code>boolean</code>
170通过getSimpleData获取数据时,日期字段是否转化为long型,如果为true时不进行转化,为false时转化为long型
171
172**Default**: <code>false</code>
173<a name="DataTable.copyRow"></a>
174
175### DataTable.copyRow(index, row)
176在指定index位置插入单条数据行
177
178
179| 参数 | Type | Description |
180| --- | --- | --- |
181| index | <code>number</code> | 数据行插入之后的位置 |
182| row | <code>object</code> | 数据行信息 |
183
184**Example**
185```js
186var row = {
187 field1:'value1'
188}
189datatable.copyRow(1,row)
190```
191<a name="DataTable.copyRows"></a>
192
193### DataTable.copyRows(index, rows)
194在指定index位置插入多条数据行
195
196
197| 参数 | Type | Description |
198| --- | --- | --- |
199| index | <code>number</code> | 数据行插入之后的位置 |
200| rows | <code>array</code> | 存储数据行信息的数组 |
201
202**Example**
203```js
204var row1 = {
205 field1:'value1'
206}
207var row2 = {
208 field1:'value1'
209}
210datatable.copyRow(1,[row1,row2])
211```
212<a name="DataTable.setData"></a>
213
214### DataTable.setData(data, options)
215设置数据信息
216
217
218| 参数 | Type | Default | Description |
219| --- | --- | --- | --- |
220| data | <code>object</code> | | 需要设置的数据信息,必须包含rows或者pages属性 |
221| [data.rows] | <code>array</code> | | 数据信息中的行信息数组 |
222| [data.pages] | <code>array</code> | | 数据信息中的page对象数组 |
223| [data.pageIndex] | <code>number</code> | <code>DataTable对象当前的页码</code> | 数据信息中的当前页码 |
224| [data.pageSize] | <code>number</code> | <code>DataTable对象当前的每页显示条数</code> | 数据信息中的每页显示条数 |
225| [data.totalPages] | <code>number</code> | <code>DataTable对象当前的总页数</code> | 数据信息中的总页数 |
226| [data.totalRow] | <code>number</code> | <code>如果存在rows则为rows的长度,否则为DataTable对象当前的总条数</code> | 数据信息中的总条数 |
227| [data.select] | <code>number</code> | | 数据信息中的选中行行号 |
228| [data.focus] | <code>number</code> | | 数据信息中的focus行行号 |
229| options | <code>object</code> | | 设置数据时的配置参数 |
230| options.unSelect | <code>boolean</code> | <code>false</code> | 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行 |
231
232**Example**
233```js
234// 不包含分页的情况
235var data = {
236 pageIndex:0,
237 pageSize:5,
238 totalPages:5,
239 totalRow:22,
240 rows:[{
241 id:'r41201', // 如果需要添加
242 status:'nrm', // 如果需要添加
243 filed1:'value1',
244 field2:'value2'
245 },{
246 id:'r41202',
247 status:'nrm',
248 filed1:'value11',
249 field2:'value21'
250 },...],
251 select:[0]
252}
253// 包含分页的情况
254var data = {
255 pageIndex:0,
256 pageSize:5,
257 totalPages:5,
258 totalRow:22,
259 pages:[{
260 index: 0,
261 select: [],
262 current: -1,
263 rows:[{
264 id:'r41201', // 如果需要添加
265 status:'nrm', // 如果需要添加
266 data:{
267 field1:'value1',
268 field2:'value2'
269 }
270 },{
271 id:'r41202',
272 status:'nrm',
273 data:{
274 field1:'value11',
275 field2:'value21'
276 }
277 },...]
278 },...],
279}
280var op = {
281 unSelect:true
282}
283datatable.setData(data,op)
284```
285<a name="DataTable.setValue"></a>
286
287### DataTable.setValue(fieldName, value, [row], [ctx])
288设置对应行对应字段的值
289
290
291| 参数 | Type | Default | Description |
292| --- | --- | --- | --- |
293| fieldName | <code>string</code> | | 需要设置的字段 |
294| value | <code>string</code> | | 需要设置的值 |
295| [row] | <code>u.row</code> | <code>当前行</code> | 需要设置的u.row对象, |
296| [ctx] | <code>\*</code> | | 自定义属性,在valuechange监听传入对象中可通过ctx获取此处设置 |
297
298**Example**
299```js
300datatable.setValue('filed1','value1') //设置当前行字段值
301var row = datatable.getRow(1)
302datatable.setValue('filed1','value1',row) //设置在指定行字段值
303datatable.setValue('filed1','value1',row,'ctx') //设置在指定行字段值,同时传入自定义数据
304```
305<a name="DataTable.isEnable"></a>
306
307### DataTable.isEnable([fieldName]) ⇒ <code>boolean</code>
308判断DataTable或指定字段是否可修改
309
310**Returns**: <code>boolean</code> - DataTable/指定字段是否可修改
311
312| 参数 | Type | Description |
313| --- | --- | --- |
314| [fieldName] | <code>string</code> | 需要进行判断的字段值 |
315
316**Example**
317```js
318datatable.isEnable() //获取datatable是否可修改
319datatable.isEnable('field1') //获取字段field1是否可修改
320```
321<a name="DataTable.setEnable"></a>
322
323### DataTable.setEnable(enable)
324设置DataTable是否可修改
325
326
327| 参数 | Type | Description |
328| --- | --- | --- |
329| enable | <code>boolean</code> | true表示可修改,否则表示不可修改 |
330
331**Example**
332```js
333datatable.setEnable(true)
334```
335<a name="DataTable.getCurrentRow"></a>
336
337### DataTable.getCurrentRow() ⇒ <code>null</code> &#124; <code>u.Row</code>
338获取DataTable对象的当前行
339
340**Returns**: <code>null</code> &#124; <code>u.Row</code> - DataTable对象的当前行
341**Example**
342```js
343datatable.getCurrentRow()
344```
345<a name="DataTable.getCurrentIndex"></a>
346
347### DataTable.getCurrentIndex() ⇒ <code>number</code>
348获取DataTable对象的当前行对应的index
349
350**Returns**: <code>number</code> - DataTable对象的当前行对应的index
351**Example**
352```js
353datatable.getCurrentIndex()
354```
355<a name="DataTable.getData"></a>
356
357### DataTable.getData() ⇒ <code>array</code>
358获取DataTable的数据信息
359
360**Returns**: <code>array</code> - 数据信息对应的数组,每项对应一条数据
361**Example**
362```js
363datatable.getData()
364```
365<a name="DataTable.getDataByRule"></a>
366
367### DataTable.getDataByRule(rule) ⇒ <code>array</code>
368按照特定规则获取数据
369
370**Returns**: <code>array</code> - 按照规则获取到的数据信息
371
372| 参数 | Type | Description |
373| --- | --- | --- |
374| rule | <code>string</code> | DataTable.SUBMIT.current('current') :当前选中行 DataTable.SUBMIT.focus('focus') :当前focus行 DataTable.SUBMIT.all('all') :所有行 DataTable.SUBMIT.select('select') :当前页选中行 DataTable.SUBMIT.change('change') :发生改变的行 DataTable.SUBMIT.empty('empty') :不获取数据,返回空数组 DataTable.SUBMIT.allSelect('allSelect') :所有页选中行 DataTable.SUBMIT.allPages('allPages') :所有页的数据 |
375
376**Example**
377```js
378datatable.getDataByRule(‘all’)
379```
380<a name="DataTable.getRow"></a>
381
382### DataTable.getRow(index) ⇒ <code>object</code>
383根据索引获取指定行数据信息
384
385**Returns**: <code>object</code> - 获取到的指定行数据信息
386
387| 参数 | Type | Description |
388| --- | --- | --- |
389| index | <code>number</code> | 需要获取的数据信息的索引 |
390
391**Example**
392```js
393datatable.getRow(1)
394```
395<a name="DataTable.getRowByRowId"></a>
396
397### DataTable.getRowByRowId(rowid) ⇒ <code>Row</code>
398根据rowid获取Row对象
399
400
401| 参数 | Type | Description |
402| --- | --- | --- |
403| rowid | <code>string</code> | 需要获取的Row对应的rowid |
404
405**Example**
406```js
407datatable.getRowByRowId('rowid')
408```
409<a name="DataTable.getRowIndex"></a>
410
411### DataTable.getRowIndex(需要获取索引的row对象) ⇒ <code>\*</code>
412获取Row对象对应的索引
413
414
415| 参数 | Type |
416| --- | --- |
417| 需要获取索引的row对象 | <code>u.Row</code> |
418
419**Example**
420```js
421var row = datatable.getRow(1)
422datatable.getRowIndex(row) // 1
423```
424<a name="DataTable.getRowsByField"></a>
425
426### DataTable.getRowsByField(field, value) ⇒ <code>array</code>
427根据字段及字段值获取所有数据行
428
429**Returns**: <code>array</code> - 根据字段及字段值获取的所有数据行
430
431| 参数 | Type | Description |
432| --- | --- | --- |
433| field | <code>string</code> | 需要获取行的对应字段 |
434| value | <code>string</code> | 需要获取行的对应字段值 |
435
436**Example**
437```js
438datatable.getRowsByField('field1','value1')
439```
440<a name="DataTable.getRowByField"></a>
441
442### DataTable.getRowByField(field, value) ⇒ <code>u.Row</code>
443根据字段及字段值获取第一条数据行
444
445**Returns**: <code>u.Row</code> - 根据字段及字段值获取第一条数据行
446
447| 参数 | Type | Description |
448| --- | --- | --- |
449| field | <code>string</code> | 需要获取行的对应字段 |
450| value | <code>string</code> | 需要获取行的对应字段值 |
451
452**Example**
453```js
454datatable.getRowByField('field1','value1')
455```
456<a name="DataTable.getAllRows"></a>
457
458### DataTable.getAllRows() ⇒ <code>array</code>
459获取当前页的所有数据行
460
461**Returns**: <code>array</code> - 获取到的数据行
462**Example**
463```js
464datatable.getAllRows()
465```
466<a name="DataTable.getAllPageRows"></a>
467
468### DataTable.getAllPageRows() ⇒ <code>array</code>
469获取所有页的所有数据行
470
471**Returns**: <code>array</code> - 获取到的数据行
472**Example**
473```js
474datatable.getAllPageRows()
475```
476<a name="DataTable.getChangedDatas"></a>
477
478### DataTable.getChangedDatas(withEmptyRow) ⇒ <code>array</code>
479获取发生变化的数据信息
480
481**Returns**: <code>array</code> - 发生变化的数据信息
482
483| 参数 | Type | Default | Description |
484| --- | --- | --- | --- |
485| withEmptyRow | <code>boolean</code> | <code>false</code> | 未发生变化的数据是否使用空行代替,true表示以空行代替未发生变化行,false相反 |
486
487**Example**
488```js
489datatable.getChangedDatas()
490```
491<a name="DataTable.getChangedRows"></a>
492
493### DataTable.getChangedRows() ⇒ <code>array</code>
494获取发生改变的Row对象
495
496**Returns**: <code>array</code> - 发生改变的Row对象
497**Example**
498```js
499datatable.getChangedRows()
500```
501<a name="DataTable.getValue"></a>
502
503### DataTable.getValue(fieldName, [row]) ⇒ <code>string</code>
504根据字段获取对应Row对象的字段值
505
506**Returns**: <code>string</code> - 获取到的字段值
507
508| 参数 | Type | Default | Description |
509| --- | --- | --- | --- |
510| fieldName | <code>string</code> | | 需要获取的值对应的字段 |
511| [row] | <code>u.Row</code> | <code>默认为当前行</code> | 对应的数据行 |
512
513**Example**
514```js
515datatable.getValue('field1')
516var row = datatable.getRow(1)
517datatable.getValue('field1',row)
518```
519<a name="DataTable.getIndexByRowId"></a>
520
521### DataTable.getIndexByRowId(rowId)
522根据行号获取行索引
523
524
525| 参数 | Type |
526| --- | --- |
527| rowId | <code>String</code> |
528
529**Example**
530```js
531datatable.getIndexByRowId('rowid')
532```
533<a name="DataTable.getAllDatas"></a>
534
535### DataTable.getAllDatas() ⇒ <code>array</code>
536获取所有行数据信息
537
538**Returns**: <code>array</code> - 所有行数据信息
539**Example**
540```js
541datatable.getAllDatas()
542```
543<a name="DataTable.getRowIdsByIndices"></a>
544
545### DataTable.getRowIdsByIndices(indices) ⇒ <code>array</code>
546根据索引获取rowid
547
548**Returns**: <code>array</code> - 获取到的rowid
549
550| 参数 | Type | Description |
551| --- | --- | --- |
552| indices | <code>array</code> | 需要获取rowid的索引值 |
553
554**Example**
555```js
556datatable.getRowIdsByIndices([1,2,5])
557```
558<a name="DataTable.getRowsByIndices"></a>
559
560### DataTable.getRowsByIndices(indices) ⇒ <code>array</code>
561根据索引获取row
562
563**Returns**: <code>array</code> - 获取到的row
564
565| 参数 | Type | Description |
566| --- | --- | --- |
567| indices | <code>array</code> | 需要获取rowid的索引值 |
568
569**Example**
570```js
571datatable.getRowIdsByIndices([1,2,5])
572```
573<a name="DataTable.getFocusRow"></a>
574
575### DataTable.getFocusRow() ⇒ <code>u.Row</code>
576获取焦点行
577
578**Returns**: <code>u.Row</code> - 焦点行
579**Example**
580```js
581datatable.getFocusRow()
582```
583<a name="DataTable.getFocusIndex"></a>
584
585### DataTable.getFocusIndex() ⇒ <code>number</code>
586获取焦点行索引
587
588**Returns**: <code>number</code> - 焦点行索引
589**Example**
590```js
591datatable.getFocusIndex()
592```
593<a name="DataTable.getMeta"></a>
594
595### DataTable.getMeta([fieldName], [key]) ⇒ <code>object</code>
596获取meta信息
597
598**Returns**: <code>object</code> - meta信息
599
600| 参数 | Type | Description |
601| --- | --- | --- |
602| [fieldName] | <code>string</code> | 需要获取的字段 |
603| [key] | <code>string</code> | 需要获取的字段指定meta信息 |
604
605**Example**
606```js
607datatable.getMeta() // 获取所有meta信息
608datatable.getMeta('field1') // 获取field1所有meta信息
609datatable.getMeta('field1','type') // 获取field1的key信息
610```
611<a name="DataTable.getRowMeta"></a>
612
613### DataTable.getRowMeta([fieldName], [key]) ⇒ <code>object</code>
614获取当前行的meta信息,如果不存在当前行则获取DataTable的meta信息
615
616**Returns**: <code>object</code> - meta信息
617
618| 参数 | Type | Description |
619| --- | --- | --- |
620| [fieldName] | <code>string</code> | 需要获取的字段 |
621| [key] | <code>string</code> | 需要获取的字段指定meta信息 |
622
623**Example**
624```js
625datatable.getRowMeta() // 获取当前行所有meta信息
626datatable.getRowMeta('field1') // 获取当前行field1所有meta信息
627datatable.getRowMeta('field1','type') // 获取当前行field1的key信息
628```
629<a name="DataTable.getParam"></a>
630
631### DataTable.getParam(key) ⇒ <code>\*</code>
632获取参数参数值
633
634**Returns**: <code>\*</code> - 参数参数值
635
636| 参数 | Type | Description |
637| --- | --- | --- |
638| key | <code>string</code> | 参数对应的key |
639
640**Example**
641```js
642datatable.getParam('param1')
643```
644<a name="DataTable.getSelectedIndex"></a>
645
646### DataTable.getSelectedIndex() ⇒ <code>number</code>
647获取选中行索引,多选时,只返回第一个行索引
648
649**Returns**: <code>number</code> - 选中行索引
650**Example**
651```js
652datatable.getSelectedIndex()
653```
654<a name="DataTable.getSelectedIndices"></a>
655
656### DataTable.getSelectedIndices() ⇒ <code>array</code>
657获取选中的所有行索引数组
658
659**Returns**: <code>array</code> - 所有行索引数组
660**Example**
661```js
662datatable.getSelectedIndices()
663```
664<a name="DataTable.getSelectedDatas"></a>
665
666### DataTable.getSelectedDatas([withEmptyRow]) ⇒ <code>array</code>
667获取选中行的数据信息
668
669**Returns**: <code>array</code> - 发生变化的数据信息
670
671| 参数 | Type | Default | Description |
672| --- | --- | --- | --- |
673| [withEmptyRow] | <code>boolean</code> | <code>false</code> | 未选中的数据是否使用空行代替,true表示以空行代替未选中行,false相反 |
674
675**Example**
676```js
677datatable.getSelectedDatas()
678datatable.getSelectedDatas(true)
679```
680<a name="DataTable.getSelectedRows"></a>
681
682### DataTable.getSelectedRows() ⇒ <code>array</code>
683获取选中的Row对象
684
685**Returns**: <code>array</code> - 选中的Row对象
686**Example**
687```js
688datatable.getSelectedRows()
689```
690<a name="DataTable.getSimpleData"></a>
691
692### DataTable.getSimpleData([options]) ⇒ <code>array</code>
693获取数据信息,只获取字段名与字段值
694
695**Returns**: <code>array</code> - 获取到的数据信息
696
697| 参数 | Type | Default | Description |
698| --- | --- | --- | --- |
699| [options] | <code>object</code> | | [description] |
700| [options.type] | <code>string</code> | <code>&quot;all&quot;</code> | 获取数据的规则 all:所有数据 current:当前行数据 focus:焦点行数据 select:选中行数据 change:发生改变的数据 |
701| [options.fields] | <code>array</code> | | 需要获取数据的字段名数组 |
702
703**Example**
704```js
705datatable.getSimpleData() // 获取所有数据信息
706datatable.getSimpleData({type:'current'}) // 获取当前行数据信息
707datatable.getSimpleData({type:'current','fields':['filed1','field3']}) // 获取当前行field1和filed3数据信息
708```
709<a name="DataTable.setMeta"></a>
710
711### DataTable.setMeta(fieldName, key, value)
712设置meta信息
713
714
715| 参数 | Type | Description |
716| --- | --- | --- |
717| fieldName | <code>string</code> | 需要设置meta信息的字段名 |
718| key | <code>string</code> | meta信息的key |
719| value | <code>string</code> | meta信息的值 |
720
721**Example**
722```js
723datatable.setMeta('filed1','type','string')
724```
725<a name="DataTable.updateMeta"></a>
726
727### DataTable.updateMeta(meta)
728更新meta信息
729
730
731| 参数 | Type | Description |
732| --- | --- | --- |
733| meta | <code>object</code> | 需要更新的meta信息 |
734
735**Example**
736```js
737var metaObj = {supplier: {meta: {precision:'3', default: '0239900x', display:'显示名称'}}}
738datatable.updateMeta(metaObj)
739```
740<a name="DataTable.addParam"></a>
741
742### DataTable.addParam(key, value)
743增加参数参数
744
745
746| 参数 | Type | Description |
747| --- | --- | --- |
748| key | <code>string</code> | 需要增加的key值 |
749| value | <code>\*</code> | 需要增加的具体指 |
750
751**Example**
752```js
753datatable.addParam('precision','3')
754```
755<a name="DataTable.addParams"></a>
756
757### DataTable.addParams(params)
758增加多个参数参数
759
760
761| 参数 | Type | Description |
762| --- | --- | --- |
763| params | <code>object</code> | 需要增加的参数对象 |
764
765**Example**
766```js
767var paramsObj = {
768 'precision':'3',
769 'default':'1.234'
770}
771datatable.addParams(paramsObj)
772```
773<a name="DataTable.refSelectedRows"></a>
774
775### DataTable.refSelectedRows(fieldName)
776为选中行绑定监听,当选中行发生改变时触发对应方法
777
778
779| 参数 | Type | Description |
780| --- | --- | --- |
781| fieldName | <code>string</code> | 绑定的字段名 |
782
783**Example**
784```js
785datatable.refSelectedRows().subscribe(function(){})
786```
787<a name="DataTable.ref"></a>
788
789### DataTable.ref(fieldName)
790为某个字段绑定监听,当字段发生改变时触发对应方法
791
792
793| 参数 | Type | Description |
794| --- | --- | --- |
795| fieldName | <code>string</code> | 绑定的字段名 |
796
797**Example**
798```js
799datatable.ref('field1').subscribe(function(){})
800```
801<a name="DataTable.refMeta"></a>
802
803### DataTable.refMeta(fieldName, key)
804绑定字段属性,当字段属性发生改变时触发对应方法
805
806
807| 参数 | Type | Description |
808| --- | --- | --- |
809| fieldName | <code>string</code> | 绑定的字段名 |
810| key | <code>string</code> | 绑定的属性key |
811
812**Example**
813```js
814datatable.refMeta('field1','type').subscribe(function(){})
815```
816<a name="DataTable.refRowMeta"></a>
817
818### DataTable.refRowMeta(fieldName, key)
819绑定当前行的字段属性,当字段属性发生改变时触发对应方法
820
821
822| 参数 | Type | Description |
823| --- | --- | --- |
824| fieldName | <code>string</code> | 绑定的字段名 |
825| key | <code>string</code> | 绑定的属性key |
826
827**Example**
828```js
829datatable.refRowMeta('field1','type').subscribe(function(){})
830```
831<a name="DataTable.refEnable"></a>
832
833### DataTable.refEnable(fieldName)
834绑定字段是否可修改属性,当字段可修改属性发生改变时触发对应方法
835
836
837| 参数 | Type | Description |
838| --- | --- | --- |
839| fieldName | <code>string</code> | 绑定的字段名 |
840
841**Example**
842```js
843datatable.refEnable('field1').subscribe(function(){})
844```
845<a name="DataTable.removeRowByRowId"></a>
846
847### DataTable.removeRowByRowId(rowId)
848根据rowId删除指定行
849
850
851| 参数 | Type | Description |
852| --- | --- | --- |
853| rowId | <code>string</code> | 需要删除行的rowId |
854
855**Example**
856```js
857datatable.removeRowByRowId('rowid1')
858```
859<a name="DataTable.removeRow"></a>
860
861### DataTable.removeRow(index)
862根据索引删除指定行
863
864
865| 参数 | Type | Description |
866| --- | --- | --- |
867| index | <code>number</code> | 需要删除行的索引 |
868
869**Example**
870```js
871datatable.removeRow(1)
872```
873<a name="DataTable.removeAllRows"></a>
874
875### DataTable.removeAllRows()
876删除所有行
877
878**Example**
879```js
880datatable.removeAllRows();
881```
882<a name="DataTable.removeRows"></a>
883
884### DataTable.removeRows(indices)
885根据索引数据删除多条数据行
886
887
888| 参数 | Type | Description |
889| --- | --- | --- |
890| indices | <code>array</code> | 需要删除的数据行对应数组,数组中既可以是索引也可以是row对象 |
891
892**Example**
893```js
894datatable.removeRows([1,2])
895datatable.removeRows([row1,row2])
896```
897<a name="DataTable.clear"></a>
898
899### DataTable.clear()
900清空datatable的所有数据以及分页数据以及index
901
902**Example**
903```js
904datatable.clear()
905```
906<a name="DataTable.addRow"></a>
907
908### DataTable.addRow(row)
909在最后位置添加一条数据行
910
911
912| 参数 | Type | Description |
913| --- | --- | --- |
914| row | <code>u.Row</code> | 数据行 |
915
916**Example**
917```js
918var row1 = new Row({parent: datatable})
919row1.setData({
920 field1: 'value1',
921 field2: 'value2'
922})
923datatable.addRow(row1)
924```
925<a name="DataTable.addRows"></a>
926
927### DataTable.addRows(rows)
928在最后位置添加多条数据行
929
930
931| 参数 | Type | Description |
932| --- | --- | --- |
933| rows | <code>array</code> | 数据行数组 |
934
935**Example**
936```js
937var row1 = new Row({parent: datatable})
938row1.setData({
939 field1: 'value1',
940 field2: 'value2'
941})
942var row2 = new Row({parent: datatable})
943row2.setData({
944 field1: 'value11',
945 field2: 'value22'
946})
947datatable.addRows([row1,row2])
948```
949<a name="DataTable.insertRow"></a>
950
951### DataTable.insertRow(index, row)
952在指定索引位置添加一条数据行
953
954
955| 参数 | Type | Description |
956| --- | --- | --- |
957| index | <code>number</code> | 指定索引 |
958| row | <code>u.Row</code> | 数据行 |
959
960**Example**
961```js
962var row1 = new Row({parent: datatable})
963row1.setData({
964 field1: 'value1',
965 field2: 'value2'
966})
967datatable.insertRow(1,row1)
968```
969<a name="DataTable.insertRows"></a>
970
971### DataTable.insertRows(index, rows)
972在指定索引位置添加多条数据行
973
974
975| 参数 | Type | Description |
976| --- | --- | --- |
977| index | <code>number</code> | 指定索引 |
978| rows | <code>array</code> | 数据行数组 var row1 = new Row({parent: datatable}) row1.setData({ field1: 'value1', field2: 'value2' }) var row2 = new Row({parent: datatable}) row2.setData({ field1: 'value11', field2: 'value22' }) datatable.insertRows(1,[row1,row2]) |
979
980<a name="DataTable.createEmptyRow"></a>
981
982### DataTable.createEmptyRow() ⇒ <code>u.Row</code>
983创建空行
984
985**Returns**: <code>u.Row</code> - 空行对象
986**Example**
987```js
988datatable.createEmptyRow();
989datatable.createEmptyRow({unSelect:true})
990```
991<a name="DataTable.setAllRowsSelect"></a>
992
993### DataTable.setAllRowsSelect()
994设置所有行选中
995
996**Example**
997```js
998datatable.setAllRowsSelect()
999```
1000<a name="DataTable.setRowSelect"></a>
1001
1002### DataTable.setRowSelect(index)
1003根据索引设置选中行,清空之前已选中的所有行
1004
1005
1006| 参数 | Type | Description |
1007| --- | --- | --- |
1008| index | <code>number</code> | 需要选中行的索引 |
1009
1010**Example**
1011```js
1012datatable.setRowSelect(1)
1013```
1014<a name="DataTable.setRowsSelect"></a>
1015
1016### DataTable.setRowsSelect(indices)
1017根据索引数组设置选中行,清空之前已选中的所有行
1018
1019
1020| 参数 | Type | Description |
1021| --- | --- | --- |
1022| indices | <code>array</code> | 需要选中行的索引数组 |
1023
1024**Example**
1025```js
1026datatable.setRowsSelect([1,2])
1027```
1028<a name="DataTable.addRowSelect"></a>
1029
1030### DataTable.addRowSelect(index)
1031根据索引添加选中行,不会清空之前已选中的行
1032
1033
1034| 参数 | Type | Description |
1035| --- | --- | --- |
1036| index | <code>number</code> | 需要选中行的索引 |
1037
1038**Example**
1039```js
1040datatable.addRowSelect(1)
1041```
1042<a name="DataTable.addRowsSelect"></a>
1043
1044### DataTable.addRowsSelect(indices)
1045根据索引数组添加选中行,不会清空之前已选中的行
1046
1047
1048| 参数 | Type | Description |
1049| --- | --- | --- |
1050| indices | <code>array</code> | 需要选中行的索引数组 |
1051
1052**Example**
1053```js
1054datatabel.addRowsSelect([1,2])
1055```
1056<a name="DataTable.setAllRowsUnSelect"></a>
1057
1058### DataTable.setAllRowsUnSelect([options])
1059全部取消选中
1060
1061
1062| 参数 | Type | Description |
1063| --- | --- | --- |
1064| [options] | <code>object</code> | 可选参数 |
1065| [options.quiet] | <code>boolean</code> | 如果为true则不触发事件,否则触发事件 |
1066
1067**Example**
1068```js
1069datatable.setAllRowsUnSelect() // 全部取消选中
1070datatable.setAllRowsUnSelect({quiet:true}) // 全部取消选中,不触发事件
1071```
1072<a name="DataTable.setRowUnSelect"></a>
1073
1074### DataTable.setRowUnSelect(index)
1075根据索引取消选中
1076
1077
1078| 参数 | Type | Description |
1079| --- | --- | --- |
1080| index | <code>number</code> | 需要取消选中的行索引 |
1081
1082**Example**
1083```js
1084datatable.setRowUnSelect(1)
1085```
1086<a name="DataTable.setRowsUnSelect"></a>
1087
1088### DataTable.setRowsUnSelect(indices)
1089根据索引数组取消选中
1090
1091
1092| 参数 | Type | Description |
1093| --- | --- | --- |
1094| indices | <code>array</code> | 需要取消选中的行索引数组 |
1095
1096**Example**
1097```js
1098datatable.setRowsUnSelect([1,2])
1099```
1100<a name="DataTable.toggleAllSelect"></a>
1101
1102### DataTable.toggleAllSelect()
1103当全部选中时取消选中,否则全部选中
1104
1105<a name="DataTable.setRowFocus"></a>
1106
1107### DataTable.setRowFocus(index, [quiet], [force])
1108设置焦点行
1109
1110
1111| 参数 | Type | Description |
1112| --- | --- | --- |
1113| index | <code>number</code> &#124; <code>u.Row</code> | 行对象或者行index |
1114| [quiet] | <code>boolean</code> | 如果为true则不触发事件,否则触发事件 |
1115| [force] | <code>boolean</code> | 如果为true当index行与已focus的行相等时,仍然触发事件,否则不触发事件 |
1116
1117**Example**
1118```js
1119datatable.setRowFocus(1) // 设置第二行为焦点行
1120datatable.setRowFocus(1,true) // 设置第二行为焦点行,不触发事件
1121datatable.setRowFocus(1,false,true) // 设置第二行为焦点行,如果当前焦点行为第二行,仍旧触发事件
1122```
1123<a name="DataTable.setRowUnFocus"></a>
1124
1125### DataTable.setRowUnFocus()
1126焦点行反选
1127
1128**Example**
1129```js
1130datatable.setRowUnFocus()
1131```
1132<a name="DataTable.setSimpleData"></a>
1133
1134### DataTable.setSimpleData(data, [options])
1135设置数据, 只设置字段值
1136
1137
1138| 参数 | Type | Default | Description |
1139| --- | --- | --- | --- |
1140| data | <code>array</code> | | 数据信息 |
1141| [options] | <code>boject</code> | | 可配置参数 |
1142| [options.unSelect] | <code>boject</code> | <code>false</code> | 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行 |
1143
1144**Example**
1145```js
1146var data = [{
1147 filed1:'value1',
1148 field2:'value2'
1149},{
1150 filed1:'value11',
1151 field2:'value21'
1152}]
1153datatable.setSimpleData(data)
1154datatable.setSimpleData(data,{unSelect:true})
1155```
1156<a name="DataTable.addSimpleData"></a>
1157
1158### DataTable.addSimpleData(data, [status], [options])
1159追加数据, 只设置字段值
1160
1161
1162| 参数 | Type | Default | Description |
1163| --- | --- | --- | --- |
1164| data | <code>array</code> | | 数据信息 |
1165| [status] | <code>string</code> | <code>&quot;nrm&quot;</code> | 追加数据信息的状态,参照Row对象的状态介绍 |
1166| [options] | <code>boject</code> | | 可配置参数 |
1167| [options.unSelect] | <code>boject</code> | <code>false</code> | 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行 |
1168
1169**Example**
1170```js
1171var data = [{
1172 filed1:'value1',
1173 field2:'value2'
1174},{
1175 filed1:'value11',
1176 field2:'value21'
1177}]
1178datatable.addSimpleData(data,Row.STATUS.NEW)
1179datatable.addSimpleData(data, null, {unSelect:true})
1180```
1181<a name="DataTable.on"></a>
1182
1183### DataTable.on(name, [callback], [one]) ⇒ <code>[DataTable](#DataTable)</code>
1184为DataTable对象添加监听
1185
1186**Returns**: <code>[DataTable](#DataTable)</code> - 当前的DataTable对象
1187
1188| 参数 | Type | Description |
1189| --- | --- | --- |
1190| name | <code>string</code> &#124; <code>array</code> &#124; <code>object</code> | 针对不同用法分别对应监听名称、监听名称对应的数组、监听名称及对应的回调组成的对象 |
1191| [callback] | <code>function</code> | 监听对应的回调函数 |
1192| [one] | <code>boolean</code> | 是否只执行一次监听,为true则表示只执行一次回调函数,否则每次触发监听都是执行回调函数 |
1193
1194**Example**
1195```js
1196datatable.on(u.DataTable.ON_ROW_FOCUS, function() {}) // 普通
1197datatable.on([u.DataTable.ON_INSERT, u.DataTable.ON_DELETE], function() {}) // 数组
1198datatable.on({u.DataTable.ON_INSERT: function() {}, u.DataTable.ON_DELETE: function() {}}) // map
1199```
1200<a name="DataTable.off"></a>
1201
1202### DataTable.off(name, [callback]) ⇒ <code>[DataTable](#DataTable)</code>
1203为DataTable对象取消监听
1204
1205**Returns**: <code>[DataTable](#DataTable)</code> - 当前的DataTable对象
1206
1207| 参数 | Type | Description |
1208| --- | --- | --- |
1209| name | <code>string</code> &#124; <code>array</code> &#124; <code>object</code> | 针对不同用法分别对应监听名称、监听名称对应的数组、监听名称及对应的回调组成的对象 |
1210| [callback] | <code>function</code> | 监听对应的回调函数 |
1211
1212**Example**
1213```js
1214datatable.off(u.DataTable.ON_ROW_FOCUS, function() {}) // 普通
1215datatable.off([u.DataTable.ON_INSERT, u.DataTable.ON_DELETE], function() {}) // 数组
1216datatable.off({u.DataTable.ON_INSERT: function() {}, u.DataTable.ON_DELETE: function() {}}) // map
1217```
1218<a name="DataTable.one"></a>
1219
1220### DataTable.one(name, [callback])
1221为DataTable对象添加只执行一次的监听
1222
1223
1224| 参数 | Type | Description |
1225| --- | --- | --- |
1226| name | <code>string</code> &#124; <code>array</code> &#124; <code>object</code> | 针对不同用法分别对应监听名称、监听名称对应的数组、监听名称及对应的回调组成的对象 |
1227| [callback] | <code>function</code> | 监听对应的回调函数 |
1228
1229**Example**
1230```js
1231datatable.one(u.DataTable.ON_ROW_FOCUS, function() {}) // 普通
1232datatable.one([u.DataTable.ON_INSERT, u.DataTable.ON_DELETE], function() {}) // 数组
1233datatable.one({u.DataTable.ON_INSERT: function() {}, u.DataTable.ON_DELETE: function() {}}) // map
1234```
1235<a name="DataTable.trigger"></a>
1236
1237### DataTable.trigger(name) ⇒ <code>[DataTable](#DataTable)</code>
1238触发DataTable对象绑定的事件监听
1239
1240**Returns**: <code>[DataTable](#DataTable)</code> - 当前的DataTable对象
1241
1242| 参数 | Type | Description |
1243| --- | --- | --- |
1244| name | <code>string</code> | 需要触发的事件监听对应的名称 |
1245
1246**Example**
1247```js
1248datatable.trigger('valuechange')
1249```
1250<a name="resetAllValue"></a>
1251
1252## resetAllValue()
1253重置所有行的数据至nrm状态时的数据
1254
1255<a name="resetValueByRow"></a>
1256
1257## resetValueByRow(row)
1258根据row对象重置数据至nrm状态时的数据
1259
1260
1261| 参数 | Type | Description |
1262| --- | --- | --- |
1263| row | <code>u.row</code> | 需要重置数据的row对象 |
1264